Hi,i have made a script,once i press “n’” button the cube stick to wall,what i want to do is,i want that only happen when i come close to cube not i can do that at any place of map,just when i come close to cube,then i can only press “n” button and then its gonna stick to wall,i know there needs to use raycast to apply action distance,but i cant do that,i dont have such experience,so im asking you for help,please help me ![]()
P.S. More like pickup distance…or something.
Here is the script:
var jointExist : boolean;
function OnCollisionEnter(c : Collision) {
if(!jointExist){
var joint = gameObject.AddComponent(FixedJoint);
joint.connectedBody = c.rigidbody;
jointExist = true;
}
}
function Update(){
if(Input.GetKeyDown(KeyCode.N)){
var joint = gameObject.GetComponent(FixedJoint);
Destroy(joint);
jointExist = false;
}
}