x


Animate my child only?

Hello! :)

I have a scene with multiple instances of a gameobject is it possible to script:

If this gameObject plays animation idle > play this game objects child animation idle

I tried find but that gives me all the instances children :(

function Update () {

if animation.Play == (idle)
var child = transform.Find("sootje"); 
child.animation.Play(idle);

if animation.Play == (walk)
var child = transform.Find("sootje"); 
child.animation.Play(walk);

if animation.Play == (jump)
var child = transform.Find("sootje"); 
child.animation.Play(jump);

}
more ▼

asked Jun 13 '10 at 12:33 PM

RemiX gravatar image

RemiX
4 3 3 4

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You're using the wrong function to see if an animation is playing. Honestly I don't know why that even compiles, other than some weird javascript reason that a string can evaluate to a bool..

Here's the documentation for animation.Play http://unity3d.com/support/documentation/ScriptReference/Animation.Play.html

What you want to use is animation.IsPlaying( animationName ), documentation here: http://unity3d.com/support/documentation/ScriptReference/Animation.IsPlaying.html

You also probably don't want to be checking it every frame without seeing if the animation is already being played, otherwise it will restart every frame and look wrong.

So try something like this.

void Update()
{
   if( animation.IsPlaying( "idle" ) )
   {
      if( !child.animation.IsPlaying( "idle" ) )
      {
          child.animation.Play( "idle" );
      }
   }
}
more ▼

answered Jun 13 '10 at 05:53 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

(comments are locked)
10|3000 characters needed characters left
function Update () {

var child = transform.Find("sootje"); 

    if (animation.Play == ("idle"))
    child.animation.Play("idle");

    if (animation.Play == ("walk"))
    child.animation.Play("walk");

    if (animation.Play == ("jump"))
    child.animation.Play("jump");

}

this is what I have now, the child is not responding :(

more ▼

answered Jun 13 '10 at 01:12 PM

RemiX gravatar image

RemiX
4 3 3 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3806
x413

asked: Jun 13 '10 at 12:33 PM

Seen: 1587 times

Last Updated: Jun 13 '10 at 12:53 PM