Having an issue using Raycast to detect a GameObject when the player looks at it. here is my code and it will compile and run with no errors, but won’t return anything when I look at a cube that I have tagged with the name “enemy”. Thanks in advance folks.
using UnityEngine;
using System.Collections;
public class bulletShoot : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
float distanceToGround = 0.0f;
RaycastHit hit;
if (Physics.Raycast (transform.position, -Vector3.up, out hit, 100.0f))
{
distanceToGround = hit.distance;
if(hit.Equals(GameObject.FindGameObjectWithTag("enemy")))
{
Debug.Log("You have hit the enemy");
Debug.Log("Distance to enemy: ");
Debug.Log(distanceToGround);
}
}
}
}