I would like to use RigidbodyConstraints.FreezeRotation;
in order to freeze the rotation of an object that is picked up. The problem is I don’t know how to refer (or call) the currently selected object. The script in it’s currents state is below…
public class PhysGun : MonoBehaviour
{
private GameObject Player;
void Start ()
{
Player = GameObject.Find("Player");
}
// Update is called once per frame
void Update ()
{
Vector3 fwd = transform.forward; // Equivalent to the code you had.
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
if (Input.GetMouseButton(0) && Physics.Raycast(ray, out hit, 10f))
{
hit.transform.SetParent(Player.transform);
Debug.Log("We hit: " + hit.transform.name);
hit.transform. = RigidbodyConstraints.FreezeRotation;
}
}
}
So, how do I call (or refer to) the object that is hit by the ray cast exactly?