I’m a total noob with code, and I was wondering how to use the cursor to interact (pick up/play) with in game objects? Any help would be amazing! Thanks!
Doug
I’m a total noob with code, and I was wondering how to use the cursor to interact (pick up/play) with in game objects? Any help would be amazing! Thanks!
Doug
There are lots of different ways to do this
So I’ll start for you so you can take it from there.
var hitObject : GameObject;
var Range : float = 1;
function Update (){
var fwd = transform.TransformDirection (Vector3.forward);
var hit : RaycastHit;
if(Physics.Raycast (transform.position, fwd, hit, Range)){
Debug.DrawRay(transform.position, fwd * Range, Color.red);
hitObject = hit.collider.gameObject
if(Input.GetKeyDown(KeyCode.E)){
hitObject.transform.parent = gameOject.transfom;
return true;
}
}
}
}
I don’t know if this will work not tested but I hope you can take it from there.
As I wrote this in notepad