- Home /
Question is off-topic or not relevant
How can I increase the value of a variable?
Hi, I am trying to make a quicktime event thing when I enter a trigger the E key pops up, and you must press the E key 30 times and then a animation will play. How can I accomplish this? I've tried, but it didn't work. The variable Presses dosen't want to increase.
Here's my script:
var Ekey : GUITexture;
var Cube : GameObject;
var Presses = 00.0;
var MaxPresses = 30.0;
function OnTriggerEnter () {
Ekey.enabled = true;
if(Input.GetButtonDown("E")){
if(Presses < MaxPresses){
Ekey.animation.Play();
Presses += 1;
if(Presses > MaxPresses){
Ekey.enabled = false;
Cube.animation.Play();
}
}
}
}
function OnTriggerExit () {
if(Presses < 30){
Presses = 0;
Ekey.enabled = false;
}
else
if(Presses == 30){
Presses = 30;
Ekey.enabled = false;
}
}
Answer by ByteSheep · May 10, 2013 at 11:38 AM
OnTriggerEnter only gets called once, if you want the function to be called every frame that the collider is within the trigger then you can use OnTriggerStay() instead.
Follow this Question
Related Questions
How to assign "data" in script at runtime 0 Answers
Unity thinks my animation is not attached, but it is. 2 Answers
Unknown identifier, OnCollisionEnter Error 1 Answer
set variable when active 1 Answer
Can I make variables visible to other scripts without making them visible in the Inspector? 1 Answer