- Home /
Script for counting not working properly
I am trying to figure out the problem with the following script, but I do not understand why the GUI text is not working properly. I want this script to start counting from 10 down to 0, every time when I press the left mouse button. Currently, the script is working in a strange way, as fast as the milliseconds count up to infinity, I do not understand the problem I tried to change all values but without result. Some Suggested?
#pragma strict
var myTrigger : GameObject;
var myObject : GameObject;
var countAmmo : int = 10 ;
private var score : int = 10;
var guiScore : GUIText;
function Start ()
{
guiScore.text = "Score: 10";
}
function Update()
{
if(Input.GetButtonDown("Fire1"))
countAmmo = countAmmo -1;
if(countAmmo == 0)
{
myObject.SetActive(false);
}
else
{
score -= 10;
guiScore.text = "Score: " + score;
myObject.SetActive(true);
}
}
Answer by Sondre-S · May 03, 2015 at 06:51 PM
This should do it
var Key: bool;
var countAmmo : int = 10 ;
start(){}
update(){
if(Input.GetButtonDown("Fire1") && Key) {
countAmmo -= 1;
Key=false;
}
else if(!Input.GetButtonDown("Fire1") && !Key){Key = true;}
}
Hello thanks for the reply. I get this error. - The name 'bool' does not denote a valid type ('not found').
Oh yeah, sorry I'm not usually coding in javascript;) just replace "bool" with "boolean".
Your answer
Follow this Question
Related Questions
Ammo Count on Gun 1 Answer
Simple Point system 3 Answers
Countdown by pressing a button. 2 Answers
Score System help 1 Answer
Score going up every second 1 Answer