Hi im making a top down survival shooting game, i have put the enemy, idle, attack and walk animations into the animator controller for the enemy object, in the enemy script which moves the enemy towards the player i am trying to link it to the animator with no success.
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
Animator anim;
public Transform target;
public float speed = 20f;
private float minDistance = 1f;
private float range;
void Update ()
{
Movement ();
}
void Movement()
{
range = Vector2.Distance(transform.position, target.position);
if (range > minDistance)
{
Debug.Log(range);
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
anim.SetFloat("Speed", speed);
}
}
}
That is my script, but i receive the error,
NullReferenceException: Object reference not set to an instance of an object
Enemy.Update () (at Assets/Scripts/Enemy.cs:17)
Any help with this would be greatly appreciated im a beginner with unity