I’m having a problem. Im trying to make that when i look at enemy isView goes to true. When i look away it’ll go false. Right now its not toggling at all. Whats the problem?
using UnityEngine;
using System.Collections;
public class enemyAI : MonoBehaviour {
public Transform player;
public bool isView = false;
void Update()
{
isView = false;
var Distance = Vector3.Distance(player.position, transform.position);
if(Distance > 30 && isView == false){
Vector3 position = player.position;
float distance = Random.Range(10.0f,20.0f);
Vector3 objPosition = position - player.forward* distance;
Vector3 startHit = objPosition;
transform.position = objPosition;
}
}
void OnWillRenderObject() {
RaycastHit hit;
if (Physics.Raycast(player.position, (transform.position - player.position).normalized, out hit)) {
if (hit.collider.gameObject == gameObject)
{
isView = true;
}
}
}
}