Made a simple raycast script, but it doesn’t work when I’m close to the object. I have to take a couple steps back. Why might this be?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Laser : MonoBehaviour
{
public Camera PlayerCamera;
void Update()
{
RaycastHit hit;
if (Input.GetKeyDown(KeyCode.E))
{
if (Physics.Raycast(transform.position, transform.forward, out hit, 4.0F) && hit.transform.tag == "cube")
{
hit.transform.parent = PlayerCamera.transform;
hit.transform.GetComponent<Rigidbody>().useGravity = false;
hit.transform.position = new Vector3(0, 0, 0);
}
else
{
Debug.Log("you arent hitting anything");
}
}
}
}