Quantcast
Viewing all articles
Browse latest Browse all 1488

Debug.log not working with raycast

Hi guys, its my first time here! I want an enemy that uses raycasts to detect me, the player. Im setting up the raycast and a test debug log to see if it works, but it does not. On my enemy I put a sphere and put a collider with is trigger on it. The problem is that even tho it enters the trigger, it does not show the debug message. using UnityEngine; using System.Collections; public class EnemyAI : MonoBehaviour { private GameObject playerTarget; private SphereCollider col; void Awake () { playerTarget = GameObject.FindGameObjectWithTag ("Player"); col = GetComponent(); } void OnTriggerEnter (Collider other) { if(other.gameObject == playerTarget) { Vector3 direction = playerTarget.transform.position - transform.position; { RaycastHit hit; if(Physics.Raycast(transform.position, direction.normalized, out hit, col.radius)) { if(hit.collider.gameObject == playerTarget) { Debug.Log ("player in sight"); //Stuff happens that makes the enemy chase the player } } } } } } I hope somebody can help me with this one because I'm completely stuck now...

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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