- Home /
parent player to object when you press a button a set amount of time
Is there a way to do this? So far I have a parenting code but it doesn't seem to last long enough for me to know if it works or not.
var prefab: Transform; var Parent : GameObject; var Map3 : Transform;
function Update () { if (Input.GetKeyDown("z")){ transform.parent = Map3.gameObject.transform; } else transform.parent= null; if (Input.GetKeyDown("z")){ transform.parent = Map3.gameObject.transform; } else transform.parent= null; if (Input.GetKeyDown("z")){ transform.parent = Map3.gameObject.transform; } else transform.parent= null; if (Input.GetKeyDown("z")){ transform.parent = Map3.gameObject.transform; } else transform.parent= null; }
Answer by Ben Holmes · Apr 25, 2011 at 07:02 PM
try using Input.GetKey(). this will continue to return true as long as you hold down the key. Also instead of setting the parent to null every frame you could keep track of how long it has been since you set the parent and only set it to null after a couple of seconds.
Your answer
Follow this Question
Related Questions
Temporary Parenting through Scripting 2 Answers
JCar & FPS/TPS controller 1 Answer
Parenting and Unparenting a GameObject that has a Rigidbody 2 Answers
Parenting after X time with collision, I dont get it! 1 Answer
Unparent object on collision? 3 Answers