OnTriggerEnter animation question
Hello there. I started to learn unity about 1 week ago. I've done my player controller with animation, so it works clearly.
Now I want to add boss animation when the player touches the Trigger. But it doesnt work. The boss (robot) is flipping (its work correctly) but his animation (SunJacking) doesn't play. I've done the transition between "Any State" and "SunJacking". The bool parameter has been done too (came). I've tried to use "SetBool" and "anim.Play" too. So here is my code. Hope you will help me with my learning x).
Best wishes, Awaking
using UnityEngine;
public class SunChap1 : MonoBehaviour
{
public GameObject player;
public GameObject robot;
private Animator anim;
private Animation an1;
void Start()
{
anim = GetComponent<Animator>();
an1 = GetComponent<Animation>();
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Flip(robot);
// anim.SetBool("Came", true); //my first try
// anim.Play("SunJacking"); //my second try
}
}
void Flip(GameObject robot)
{
Vector2 theScale = transform.localScale;
theScale.x = 1;
robot.transform.localScale = theScale;
}
}
hey dude,take a screenshot of your animator window and place it here,maybe it helps :). because your code seems to be fine :).
Answer by PersianKiller · Sep 09, 2017 at 02:47 AM
your code and animator window seems fine. dude I have a question,If you click on the Came bool in the animator window,then Sunjacking animation will play?
because you're using OnTriggerEnter2D ,it means that at least one of your objects should has a rigidbody2D and they both should have boxCollider2D component and at least one of them should has a trigger boxCollider2D .please check this.
Yea. $$anonymous$$y animation plays if Bool = true. Player has rigidbody2d and boxcollider2d. robot has boxcollider2d (as trigger). Also I tried to add an additional boxcollider to empty gameobject but it doesnt work too. :/ I have no idea what should I do to work my animation :c
Added attachments to see the setting of robot and player
does your player have a Player tag? if it does,every thing looks O$$anonymous$$ !!!!!
yea, my player has. cuz i use it in the other procedure (death tag) also the robot flips when the trigger is activating but animation doesnt work if (other.tag == "Player") { Flip(robot); // anim.SetBool("Came", true); //my first try // anim.Play("SunJacking"); //my second try }