using UnityEngine;
using System.Collections;
public class GoblinAttack : MonoBehaviour {
public GameObject goblin;
public float distance;
public Animator anim;
public float speed;
public float health;
public GameObject player;
public bool walking = false;
public bool attacking = false;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
float step = speed * Time.deltaTime;
goblin = GameObject.Find ("firstgoblin");
player = GameObject.Find ("FPSController");
distance = Vector3.Distance(goblin.transform.position, player.transform.position);
if (distance < 10){
transform.position = Vector3.MoveTowards(transform.position, player.transform.position, step);
walking = true;
anim.Play ("walking", -1, 0f);
if (distance < 3){
attacking = true;
}
}
}
}
I have this script and it is supposed to make the goblin move toward me and start the walking animation if I’m closer than 10 units. It moves me and starts the animation, but every frame… It is checking the distance every frame, and if the distance is less than 10, it starts the animation over. How do I make the animation play through before it loops?