Hello, I’m new in unity. I’ve been doing a FPS game, with enemies.
I’ve started doing the sight of the enemies, but doing the debug, something happened.
Sight only worked when the enemy collided with something that was not the terrain.
Here’s my code. I’ll appreciate any solutions.
using UnityEngine;
using System.Collections;
public class EnemyVisionRaycast : MonoBehaviour {
private Vector3 dir;
// Update is called once per frame
void FixedUpdate () {
RaycastHit hit;
dir = transform.rotation.eulerAngles;
Ray vision = new Ray (transform.position, dir);
Debug.DrawRay(transform.position,dir,new Color(0,0,0,100));
if (Physics.Raycast (vision,out hit, 100))
{
if (hit.collider.CompareTag ("PlayerTag")) {
Debug.Log ("It works");
}
}
}
}
Oh, the enemy is a prefab.
-AlexINF