Hello everyone,
I got a small problem. I created an animated sprite by dragging to to editor my sliced spritesheet, as you do. Then I added to this sprite a box collider which I made a trigger.
The idea here is that when the player enters the trigger, the animation plays once, and stop at the last frame. When the player is not in the trigger, the animation should not play.
No matter what I do, it doesn’t work. Here is some code :
void OnTriggerEnter2D (Collider2D other){
Debug.Log("Chest opens");
Debug.Log(other.gameObject.tag);
if(other.gameObject.tag == "Player"){
Debug.Log("Chest opens");
this.GetComponent<Animator>().Play("chest_o");
isOpened = true;
}
}
When the player enters the trigger, the tag is recognized as “Player” so that is not the problem. Still, no animation.
To give more detail, to prevent the animation to play automatically when I launch the game, I added a :
void Start () {
this.GetComponent<Animator> ().Stop ();
}
Can somebody tell me what is not done as it should ?
Thanks a lot.