Raycast does not seem to be hitting colliders. My walls are in their own layer but putting them in the default layer did not change anything. The Debug.DrawRay() and Debug.Log(hi1.transform.name) are not returning anything but I'm sure the Shoot() method is being invoked because of my other Debug.Logs.
public class ShootP1 : MonoBehaviour
{
public GameObject Shooter;
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown("r"))
{
Shoot();
//Debug.Log("Pressed");
}
}
void Shoot()
{
RaycastHit hit1;
//Debug.Log("shot");
if (Physics.Raycast(Shooter.transform.position, Shooter.transform.forward, out hit1, 1000))
{
Debug.DrawRay(Shooter.transform.position, Shooter.transform.forward, Color.cyan);
Debug.Log(hit1.transform.name);
}
}
↧