so i have a an enemy in a room. i only want the enemy to move and attack when the player is in the room so i have put a trigger on the floor with this script:
using UnityEngine;
using System.Collections;
public class trigger : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void OnTriggerEnter (Collider Player) {
if (Player.CompareTag("Player")){
Debug.Log (Player.gameObject.name);
attackScript.Attack();
}
}
}
then i have this script attached to my enemy:
using UnityEngine;
using System.Collections;
public class attackScript : MonoBehaviour {
public Transform target;
public static attackScript attack;
// Use this for initialization
void Start () {
// Transform me = transform;
}
// Update is called once per frame
public static void Attack() {
attack.StartAttack();
}
void StartAttack(){
animation.Play ("intmidate");
transform.LookAt(target);
}
}
but i get this error:
NullReferenceException: Object reference not set to an instance of an object
i get it for this line of script:
attack.StartAttack();
any ideas how to fix this?