I have a enemy with a raycast shooting out its eyes. When the player touches the raycast, its printing “I SEE U”).
But i want it so when a wall is in the way, its not printing “I SEE YOU”.
Just like in real life. You cant see your friend, if there is a wall between you.
I dont want the enemy to see me, if there is a wall between us.
Here is my script for now.
using UnityEngine;
using System.Collections;
public class RaycastForward : MonoBehaviour {
public bool spotted = false;
// Update is called once per frame
void Update () {
RaycastHit hit;
Vector3 forward = transform.TransformDirection (Vector3.forward) * 10;
Debug.DrawRay (transform.position,forward,Color.green);
if(Physics.Raycast (transform.position,(forward), out hit)) {
Debug.DrawLine (transform.position, hit.point, Color.red);
Debug.DrawRay(transform.position,forward * 19, Color.red);
}
if(hit.transform.gameObject.tag == "Player") {
print ("I SEE U");
}
}
}