- Home /
starting the animation from a different game object
i want to play an animation from a different game object, for example, a sphere has a script that will play an animation when activated, but the animation is an another game object. how can i do this, im new to scripting so if anyone can show me how that would be great.
i think i need to add s another script to the sphere something like find a game object with the tag camera and play animation ("100")
Answer by AliAzin · Sep 12, 2010 at 11:11 AM
you should reference your target object to a variable by assigning it in inspector or other methods like finding . then you should call animation.Play() on that game object. for example:
var target : GameObject; function Start(){ target = GameObject.Find("target"); target.animation.Play();
}
Answer by xkevenx · Apr 08, 2011 at 09:46 PM
What if you wanted to change this to pause another animation that's already in progress?
When I used the code below, I get an error saying "speed is not a member of UnityEngine.Animation"
var target : GameObject;
function OnTriggerStay (info : Collider){ //uses a trigger collsion to change animation speed if (info.gameObject.tag == "car"){ //check tag name of collided object target = GameObject.Find("target"); target.animation.speed=0; yield WaitForSeconds (1); target.animation.speed=1; }
}
Answer by BranDino · Jun 15, 2013 at 04:22 AM
this totally helped me out, I got it to work without the following line of code | target = GameObject.Find("target"); | I just dragged the object that contained the animation into the variable inspector slot (attached to the object that would control when animations of other objects played), so it did not need to use the "Find" function. The result is one game object activates the animations of several other objects! thanks again! I was hung up on this for a few hours..