- Home /
How would you make your player freeze for a certain amount of time?
I want to set up my code pretty much just checking for if the space bar is pressed, my character freezes for a certain amount of time, when that amount of time is up I want the player to be able to move again.
Answer by Kossuranta · Jul 06, 2013 at 02:14 AM
Variable do see if player is frozen or not and then just timing method to remove the freeze.
Something like this:
var playerFreeze : boolean = false;
var freezeTimer : float;
function Update(){
if(!playerFreeze){
//Code that can be only used when player is not frozen
} else if(freezeTimer <= 0) {
playerFreeze = false;
} else {
freezeTimer -= Time.deltaTime;
}
Answer by Kiloblargh · Jul 06, 2013 at 02:12 AM
If the spacebar is pressed and the character controller is enabled, store Time.time
and disable its character controller.
If the character controller is disabled and the current Time.time is greater than the saved Time.time
plus the time limit, then re-enable it.
Your answer
Follow this Question
Related Questions
Unity and Playmaker - Flashlight Decrease Logic 0 Answers
How to work a real life timer? 2 Answers
Timer running down too quickly 1 Answer
A node in a childnode? 1 Answer
Timer help please 1 Answer