Im trying to have it so when the object collides with tagged object it changes to “isBlocked” but still is able to change back to the others.
using UnityEngine;
using System.Collections;
public class Chase : MonoBehaviour {
public Transform player;
static Animator anim;
void Start ()
{
anim = GetComponent<Animator>();
}
void Update ()
{
Vector3 direction = player.position - this.transform.position;
float angle = Vector3.Angle(direction,this.transform.forward);
if(Vector3.Distance(player.position, this.transform.position) < 15 && angle < 90)
{
direction.y = 0;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
Quaternion.LookRotation(direction), 0.1f);
anim.SetBool("isIdle",false);
if(direction.magnitude > 3)
{
this.transform.Translate(0,0,0.05f);
anim.SetBool("isWalking",true);
anim.SetBool("isAttacking",false);
}
else
{
anim.SetBool("isAttacking",true);
anim.SetBool("isWalking",false);
}
}
else
{
anim.SetBool("isIdle", true);
anim.SetBool("isWalking", false);
anim.SetBool("isAttacking", false);
}
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == "OhNo")
{
anim.SetBool ("isBlocked", true);
}
}
}