|
This is my current code, attached to a gameobject. It causes the gameobject to go from y position 10 to 22 but I want it to do that and then from 0 to 22, then from -20.5 to 22 and finally 13 to 22. Also, I want destination to instead point to the next array element(with the usual restriction to the array length). Thanks!
(comments are locked)
|
|
Like Ben said, you want to track the index into the array and as update is called each frame, it will take care of acting over time. Something like this: Unity js Thanks a lot! Replacing the for loop with an if loop and using a .length array editor were the two differences i noticed first.
Aug 10 '10 at 05:21 PM
maggot
Eek, just tried it, it didnt work - got this error message : ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count. Parameter name: index 4
Aug 10 '10 at 06:56 PM
maggot
Yeah, sorry about that. Typed it up in like 5 minutes. Should have incremented last. Fixed now.
Aug 12 '10 at 02:02 PM
skovacs1
(comments are locked)
|
|
It's worth taking the time to understand skovacs1's answer. If you don't understand when Update is called and how to use it, you won't get too far with Unity scripting. For the specific problem of moving objects from place to place over time, which you will encounter over and over again, you might also want to look at iTween, which is free. The command to move a game object to position 0,22,0 over the next 2 seconds would look something like this: iTween.MoveTo(gameObject,Vector3(0,22,0),2); You can queue up multiple movements, have the object start fast then slow down as it reaches the destination, and other effects. (Disclaimer: I'm planning to use it on my next project, and I expect it will save me a lot of time, but haven't have much hands-on with it yet.) Yeh, of course - I find learning the correct placement of update function calling to be one of the more interesting parts of learning unity. I'm also new to javascript :) I've heard of itween, it looks useful and simple to implement but I wanted to learn how to do animations etc first
Aug 10 '10 at 05:26 PM
maggot
Sounds good. Hope I didn't sound patronizing! I just wanted to add the additional info about iTween, without seeming to suggest that iTween replaces the usefulness of understanding Update. Carry on! :-)
Aug 11 '10 at 03:01 AM
Bampf
(comments are locked)
|

You want to at least get rid of the for loop and maintain the index outside of Update. You want Update to act like the loop as it will run repeatedly over time.
Thanks, i think the answer is given more fully below