c# - I am not sure what is going on with the for loop through GameObjects -
public void update(){ gameobject[] boxarray = new gameobject[16]{boxlid1, boxlid2, boxlid3, boxlid4, boxlid5, boxlid6, boxlid7, boxlid8, boxlid9, boxlid10, boxlid11, boxlid12, boxlid13, boxlid14, boxlid15, boxlid16}; for(int = 0; < boxarray.length; i++){ transform theboxlid = boxarray[i].transform; bluebox.transform.translate(theboxlid.localposition.x, theboxlid.localposition.y, 0); debug.log(theboxlid.localposition.x); } }
i have lids initiated above thats not problem. want bluebox move on boxlids in array not moving @ all.
i have found solution , is:
ienumerator movebluebox(){ gameobject[] boxarray = new gameobject[16]{boxlid1, boxlid2, boxlid3, boxlid4, boxlid5, boxlid6, boxlid7, boxlid8, boxlid9, boxlid10, boxlid11, boxlid12, boxlid13, boxlid14, boxlid15, boxlid16}; for(int = 0; < boxarray.length; i++){ transform thebox = boxarray[i].transform; bluebox.transform.position = new vector3(thebox.position.x, thebox.position.y, 0.0f); yield return new waitforseconds(0.1f); } }
i taking bluebox , making lay on top of every box in boxarray every 0.1 seconds looping through array , changing blueboxs transform position. main thing found out need use "new vector3" correctly move box every box in boxarrays x, y, , z coordinates.
i'm still unsure mean "move over". want move bluebox first boxlid1, boxlid2 etc.?
also make box moving need update position little bit each time update
called. can various ways, example movetowards
function of vector3
:
public class move : monobehaviour { public gameobject boxlid1; public float speed = 5.0f; public void update() { bluebox.transform.position = vector3.movetowards( bluebox.transform.position, boxlid1.transform.position, time.deltatime * speed); } }
this move bluebox
towards boxlid1
speed until reaches it. note sample code , have not testet this.
Comments
Post a Comment