- Home /
False boolean is stopping script from being used on other objects
I'm putting together an examination system for a game I'm working on and I have it working as intended, although part of the script will only work for one gameObject. When the held boolean is true I want the player's control to be off and turn it back on when it's false. The problem is, it's always false, so when I try to pick up another object it won't stop the player's control.
I'm assuming this is because it's running in the Update function. I tried to put them into their own functions and call the functions when the bool is true/false but I get the same result.
I've also written another script before that toggled on/off the player's control but that was done with two single mouse inputs and it worked as expected.
I have a script that handles the raycast interactions and will toggle the held boolean on/off. While the raycast is touching, the object's script becomes activated and turned null if it's not touching. The object's script is like this..
void Update()
{
if (held == true)
{
thisObject.transform.position = holdPos.position;
//transform.rotation = holdPos.rotation;
lockLook.Control.Toggle = false;
movelock.Control.Toggle = false;
}
else
{
thisObject.transform.position = startPos;
thisObject.transform.rotation = startRot;
lockLook.Control.Toggle = true;
movelock.Control.Toggle = true;
}
}
I had an response on Stackoverflow that said I should use
If I want to stop it from working. I've tried to use this but can't figure out how. Any help is appreciated. Thanks!if (!held) return;
Check how you turn held
on, just in case you have done something like this
if(condition){
held = true;
}
if(other condition){
held = false;
//turns held back off after a single frame
}
Your answer

Follow this Question
Related Questions
GetComponent in the Update function? 1 Answer
Three Possible Conditions, Checked in Update, Print Condition Only On Condition Change 0 Answers
My bool function isnt running in my code and i cant figure out why. 0 Answers
Making button activate update with boolean 1 Answer
Coroutines and if statements 1 Answer