I'm trying to activate some code in the Update function to pick up an object when a boolean becomes true. However, the code at the minute continuously activates whilst the boolean is true, which causes the character to rapidly pick up and drop the object. Is there a way I could set it only to activate upon the boolean becoming true, and then not to activate again until the boolean becomes false, and true again? I would prefer to do it in the update function, otherwise a large chunk of code will have to change to work with GetComponents and SendMessages and the likes.
Thanks for your help!
Here is the script, although I'm not sure it's necessary for this:
if (zButton)
{
if (!hasObject)
{
//if the fiducial cant be seen, stop this script from picking up objects
if (!renderer.enabled)
{
return;
}
if (Physics.Raycast(camera.main.transform.position, (transform.position-camera.main.transform.position), hit, 75, LayerMask))
{
otherThing = hit.transform;
if (otherThing.tag =="Moveable")
{
otherThing.rigidbody.isKinematic = true;
otherThing.rigidbody.detectCollisions = false;
otherThing.transform.position.z = 0;
otherThing.parent = transform;
otherThing.Find("Glowblock").light.enabled = true;
hasObject = true;
}
}else
{
if (otherThing.tag == "Moveable")
{
otherThing.rigidbody.isKinematic = false;
otherThing.rigidbody.detectCollisions = true;
transform.DetachChildren();
otherThing.transform.position.z = 0;
otherThing.Find("Glowblock").light.enabled = false;
hasObject = false;
//etc etc....