When Key is Pressed add one to variable
I Know my code is bad but, it would be really nice for an answer. So what i want is when KEY is pressed 1 is added to the score or also known as "money"
#pragma strict
var money : int;
var KEY : KeyCode;
function Start () {
money = 1;
}
function Update()
{
if (Input.GetKey(KEY));
{
money += 1;
Debug.Log("money$$$");
}
}
Answer by Whiteleaf · Apr 29, 2016 at 07:21 AM
There are two main problems here, firstly your 'if' statement has a semi colon ( ; ) at the end of it which leads to an empty statement, and will NOT execute the if statement.
Second, Input.GetKey is for when you're holding down the key, you want to use Input.GetKeyDown if you want to increase every time you press it.
Hope this helps!
Your answer
Follow this Question
Related Questions
How to access a variable from multiple instances and add them together 0 Answers
public variable is not being updated in script. 0 Answers
Code check. Is my Highscore saving code OK? 3 Answers
Keeping points tallied 1 Answer
In the next scene tell player there score out of total using player prefab before next level 1 Answer