Delay in setting Boolean Value
I am making a portal that will need to have a delay to set a boolean to control whether or not they can be used. I am coming over from Unreal to Unity and in Unreal, you have a delay node for these kinds of operations. I have tried to use a Wait For Seconds method and have had troubles with it.
void ResetCanTP (float delay)
{
CanTP = false;
yield WaitForSeconds(delay);
CanTP = true;
}
}
The error I am seeing is: Expected ; or = ( cannot specify arguments in declaration) No idea how to fix this issue as I am new to Unity and C#
You could invoke a switch.
In your main code, assu$$anonymous$$g switchBool is already set to false by default, you could do something like this in the Start(), so it happens 2 seconds after creating the object:
Invoke("delayedSwitch",2.0f);
Then a method:
public void delayedSwitch ()
{
switchBool=true;
}
This would mean the script is attached to the portal GameObject, and the switchBool is a variable in the same script.
Not sure if this is the approach you are looking for, but this is one approach that may work for you.
Answer by hiimachicken · Apr 19, 2019 at 09:13 PM
You need to change 'void' to 'IEnumerator'
Then call StartCoroutine(ResetCanTP(2f));
And also change your yield line to
yield return new WaitForSeconds(delay);
Your answer
Follow this Question
Related Questions
WaitForSeconds clarification 1 Answer
Could not load source 'Coroutines.cs': No source available. 1 Answer
Cannot Call Function from Another Function 1 Answer
How can I delay 1 second this code? 3 Answers
Question to WaitForEndOfFrame 2 Answers