- Home /
Recommended way to delay controls momentarily?
Hello all,
I have a camera animation that lasts a few seconds at the beginning of my game. However, the player can still move while the camera is animation is being played.
What's the best way to delay the player controls from being enabled?
Thanks in advance.
a very simple command you must master is Invoke().
so it's just something like Invoke( "turnOnControls", 2.5 );
read about it at unityGE$$anonymous$$S.com
Thanks for the help Fattie.
I made a function called myTestInvoke and used Debug.Log to see if it works. I tried different amounts of time in seconds to confirm that it works and it does. Great!
However, the problem is the controls are in the Update function.
How do you Invoke the player controls when they are in the update function?
Thanks.
Answer by Dave-Carlile · Jan 04, 2013 at 12:57 PM
Use a boolean to control whether or not input is enabled. You can set the boolean value in various ways. One way is to initialize it to false, then set it to true once the camera animation is complete.
You're checking for input in the Update function. If the boolean is false, meaning input is not enabled, then skip the input checks. If it's true, meaning the input is enabled, then do the input checks.
bool controlsEnabled = false;
void CheckInput()
{
// TODO : do your input checking here
}
void Update()
{
if (controlsEnabled)
{
CheckInput();
}
}
Answer by Piflik · Jan 03, 2013 at 10:48 AM
Create a boolean variable that you set to false if the camera is animated and only allow movement when this boolean is true.
Hi Philipp,
Thanks for the help.
Let's say I had a boolean called isCameraAnimated. How do you reference that to the actual camera being animated? How does the boolean know that the camera is animated?
Thanks again.
You would control that boolean whenever you animate the camera. If you only have one camera, you could make that variable static. Declare it in the same script that controls the camera and if it is animated set it to false (or true). After the animation is finished reset it again.
You can test if a specific animation is playing with Animation.IsPlaying("AnimationName"), Or you use a coroutine to play an AnimationClip and yield for the AnimationClip's length.
Your answer
![](https://koobas.hobune.stream/wayback/20220613090315im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can CompositeCollider2D not be disabled? 1 Answer
Bool activate/de-activate on timer C# 1 Answer
Why my player settings is disabled? Unity 5.6.1 3 Answers
Enable and Disable scripts 1 Answer