With this script, i get infinite invalid layer index errors and the animation doesn’t play:
using UnityEngine;
using System.Collections;
public class Stalker : MonoBehaviour
{
public Animator anim;
public float followSpeed = 0.1f;
public Transform followTarget;
void Awake ()
{
anim = GetComponent<Animator>();
}
void Update ()
{
this.Follow (this.followTarget, fSpeed: this.followSpeed);
}
void Follow (Transform target, float fSpeed = 1)
{
Vector3 newPosition = Vector3.MoveTowards(this.transform.position, target.position, fSpeed * Time.deltaTime);
anim.Play ("HumanoidRun");
this.transform.position = newPosition;
this.transform.LookAt (target.position, this.transform.up);
}
}
Why? What is the proper way to do this? I already watched the tutorial on animator scripting.
Please help!