I have set up the animator and all of the code, but the animation keeps looping? Help, I really can’t figure it out.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cHOPdOWNtHIStREE : MonoBehaviour {
public int Treelives;
public Animator _anim;
// Use this for initialization
void Start () {
Treelives = 10;
_anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {
_anim.Play ("Chop", -1, 0f);
}
}
void OnTriggerEnter(Collider other){
if (other.CompareTag ("Tree")) {
if (Input.GetMouseButtonDown (0)) {
Treelives -= 2;
if(Treelives == 0){
Destroy(other.gameObject);
}
}
}
}
void OnTriggerExit(Collider other){
if (other.CompareTag ("Tree")) {
Treelives = 10;
}
}
}