iTween targeting different gameobjects

I’ve just started using iTween, which has solved a lot of animation problems I was having.

However I was wondering if there is a way to talk to different gameObjects with one script?

To explain further, I have several monsters that move up and down. Each is a prefab with one script that tells them how to explode and collide give scores etc. I have the following code to make them move up and down :

function Update ()
{
iTween.MoveTo(gameObject,{"y":4.25,"time":2,"easetype":iTween.EaseType.linear,"looptype":iTween.LoopType.pingPong});
}

this however moves all the monsters up and down to the same coordinates. So would like to give each gameobject a name like enemy1, enemy2 etc and then call each object with a different line of code for the right coordinates for tht gameobject.

Thanks

var target: GameObject;  //One of your many monsters.
var eventName : String;  // One of your various iTweened monster coordinates.

function OnTriggerEnter (other: Collider){ //or which ever function type you need
         
            iTweenEvent.GetEvent(target,eventName).Play();
       }

attach this to each monster.
attach the GameObject (variable)
and type in the name of your event.(string)
This snippet assumes that you are also using the iTween Visual Editor.
Hope this helps
K

If you want to do it the hard way and script in every iTween then it may look something like this

var target :GameObject; //one of your monsters.

function Update ()
{
iTween.MoveTo(target,{"y":4.25,"time":2,"easetype":iTween.EaseType.linear,"looptype":iTween.LoopType.pingPong});
}

attach to monster.
attach the GameObject (variable)

hope this works.
K

Thanks shabazzster,

I’ve not tried the visual editor yet, but the code is working great. Thanks for you help :slight_smile: