So i am making a stealth game where i can hide in the shadows, i gave my point light a trigger and if i am in it it will debug the console. Now i want my ai to look at me if i am lit(I will add a field of view later). but i get null reference exception object reference not set to an instance of an object
here is my code Light Script:
using UnityEngine;
using System.Collections;
public class LightScript : MonoBehaviour {
public bool lighted = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider other){
if (other.gameObject.tag == "Player") {
(lighted) = true;
Debug.Log("lit");
}
}
void OnTriggerExit (Collider other){
if (other.gameObject.tag == "Player") {
(lighted) = false;
Debug.Log("unlit");
}
}
}
And here is my EnemyAI:
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed = 1;
public bool detection;
private Transform myTransform;
public LightScript detect = new LightScript();
void Awake(){
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
detection = detect.lighted;
target = go.transform;
}
// Update is called once per frame
void Update () {
Debug.DrawLine(target.transform.position, myTransform.position);
//Look At target
if(detect == true){
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
}
}
}