Script Help (43413)

Hey everyone,
just a small problem, been searching for why this isnt working. I want the object to play its animations when the object is clicked.
I have this, but it doesnt play when i click it, not sure where to go with this?

#pragma strict


function OnTriggerEnter(theObject : Collider){
    if(theObject.gameObject.name=="3rd Person Controller") {
       animation.Play("Take001");
    }
}

function OnMouseDown () {
    animation.Play("Take001");
}

Please try to format your code. Either indent it one tab or four space before pasting it, or highlight it in your question and click the code button (1s and 0s). I've done it for you this time

If you insert a debug "print" statement in the OnMouseDown function, do you see that section of code being reached? It could be that the animation doesn't play because the code isn't being reached. First thing I would do is to see if the OnMouseDown code is being called.

Are you certain the animation is even working?

1 Answer

1

The first thing i would check is like @kolban said, check if your OnMouseDown function is being called. OnMouseDown needs a collider attached to the object or it can’t detect any raycasts (OnMouseDown is just based on a raycast).

If it is called then make sure the animation works and you don’t have another script that also plays a different animation which overrides this one.