- Home /
Question by
janjoeljanjoel · Aug 22, 2020 at 02:24 PM ·
scripting problem
animation does not work when one clone got destroy unity
hi I have encountered a problem animation does not work when clone got destroy unity the slime basic task is to block my way.
here is the script;
using UnityEngine;
[RequireComponent(typeof(Animator))] public class slimeanimator : MonoBehaviour {
public static Animator animator;
protected Leftbutton LeftButton; //looking for script left buttton
protected Rigthbutton RigthButton;
public GameObject playerObj;
public GameObject EnemyObj;
public float EnemyDistance;
public float offset;
// Start is called before the first frame update
void Start()
{
offset = 9;
LeftButton = FindObjectOfType<Leftbutton>();
RigthButton = FindObjectOfType<Rigthbutton>();
playerObj = GameObject.FindGameObjectWithTag("Player");
EnemyObj = GameObject.FindGameObjectWithTag("Enemy");
}
void Awake()
{
animator = GetComponent<Animator>();
}
void Left()
{
animator.SetTrigger("WalkLeft");
}
void Right()
{
animator.SetTrigger("WalkRight") ;
}
// Update is called once per frame
void attack()
{
animator.SetTrigger("Attack02");
}
public void Update()
{
EnemyDistance = Vector3.Distance(playerObj.transform.position, EnemyObj.transform.position);
if (EnemyDistance < offset)
{
animator.SetTrigger("Attack02");
Debug.Log("Attk");
}
else
{
animator.SetTrigger("IdleNormal");
}
}
void LateUpdate()
{
if (LeftButton.Pressed)
{
Left();
Debug.Log("left");
}
else if (RigthButton.Pressed)
{
Right();
Debug.Log("rigth");
}
else
{
animator.SetTrigger("IdleNormal");
}
}
}
Comment
Best Answer
Answer by janjoeljanjoel · Aug 23, 2020 at 09:43 AM
I already solve this by changing the animator to non static