Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Enemy not detecting player

$
0
0
Hello, I'm making a turret AI and have attached a trigger to it. Once the player enters the trigger the turret should look at it. In order to do that I created a bool variable which should become false once the player enters the trigger but it's not working. Here's my script for the turret: using UnityEngine; using System.Collections; public class TurretAI : MonoBehaviour { public bool idleState = TurretSight.idleState; public float speed = 10; public Transform player; public float degree; // Use this for initialization void Start () { idleState = true; } // Update is called once per frame void Update () { if(idleState){ transform.Rotate(Vector3.up * Time.deltaTime * speed); degree += Time.deltaTime; if(degree >= 2){ speed *= -1; degree = -2; } } else transform.LookAt(player); } } And here's the turret's sight (PS: it's a custom pyramid collider from another gameobject) using UnityEngine; using System.Collections; public class TurretSight : MonoBehaviour { public static bool idleState; public GameObject player; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnTriggerStay(Collider enter){ if(enter.gameObject == player){ idleState = false; } } void OnTriggerExit(Collider exit){ if(exit.gameObject == player) idleState = false; } } Any help will be greatly appreciated. Thanks in advance.

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>