- Home /
This post has been wikified, any user with enough reputation can edit it.
Score going up like crazy
This should work this way : while a object is inside a trigger you press a key to change its material,if it leaves the trigger with the original material you lose points,with the new you win,a bool dont let you press the button infinite times or press at the wrong time.
But when i start the game the score start going up at extreme speeds without reason,in some seconds it already pass the 1000 mark.
using UnityEngine;
using System.Collections;
public class teclacima: MonoBehaviour {
public Material[] coisas;
private static bool esquilo = false;
void Update () {
if (Input.GetKeyUp("backspace") && esquilo == true)
this.renderer.sharedMaterial = coisas[1];
sistema.ponto += 1;
esquilo = false;
if(sistema.fase == 0)
{
sistema.score += 1;
}
else if(sistema.fase == 1)
{
sistema.score += 2;
}
else if(sistema.fase == 2)
{
sistema.score += 3;
}
else if(sistema.fase == 3)
{
sistema.score += 4;
}
}
void OnTriggerEnter(Collider other) {
esquilo = true;
}
void OnTriggerLeave(Collider other) {
esquilo = false;
if (this.renderer.sharedMaterial == coisas[0])
sistema.ponto -= 1;
}
}
Comment
Answer by Esa · Mar 19, 2012 at 06:18 AM
You oughto wrap the if in curlybracets {} :)
if (Input.GetKeyUp("backspace") && esquilo == true)
{
this.renderer.sharedMaterial = coisas[1];
sistema.ponto += 1;
esquilo = false;
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Score not adding? 3 Answers
Score display error 1 Answer
Score system 1 Answer
Setting Scroll View Width GUILayout 1 Answer