- Home /
Pick-Up Object With Mouse Hold
I am trying to make my game so that you can look at an object, and if close enough, pick it up by holding mouse down. I have created an empty object and placed it where I want the held object to be.
I watched a tutorial that used one script. Here is the code I am Using. It is in JavaScript:
var target : Transform;
function Update () {
}
function OnMouseDown() {
this.transform.position = target.position;
this.transform.parent = GameObject.Find("FPSController (1)").transform;
// this.transform.parent = GameObject.Find("FirstPersonCharacter").transform;
}
function OnMouseUp() {
this.transform.parent = GameObject.Find("FPSController (1)").transform;
this.transform.parent = null;
}
When I apply the script nothing happens. I walk over to the object and press the mouse button, but it does not respond to my mouse clicking.
It is worth noting that my pickUpTarget empty object is a child of FPSController but not of FirstPersonCharacter. I did this because I do not wan't the object moving up and down with the camera, just left and right.
Thanks
Your answer
Follow this Question
Related Questions
Collision Detection in Capsule Collider 0 Answers
OnCollisionEnter Push Object Problem 0 Answers
Character controller mess up damage 3 Answers
Collision CharacterController vs CharacterController 2 Answers