Is it possible to “store” the gameobject hit by raycast in a variable somehow? I am new to unity and the way I am using raycast right now seems a bit clunky, I have a script to pick up objects but I seem to have little control of the object being hit.
Here’s what I have right now:
var holdingObject : boolean = false;
function FixedUpdate () {
var hit : RaycastHit;
var forward = transform.TransformDirection(Vector3.forward);
if(Input.GetButtonDown("Fire2")){
Physics.Raycast(transform.position, forward, hit, 5);
if(hit.collider != null){
if(hit.collider.gameObject.tag == "jumpableObject" && holdingObject == false){
hit.collider.gameObject.transform.parent = transform;
hit.collider.gameObject.rigidbody.isKinematic = true;
holdingObject = true;
}
}
}
}
I have a feeling that it should be possible to store this transform from the raycast in a variable but I am not sure how, any help to get me on the right track would be appriciated :)!