- Home /
Variable bug???
// my variable named NumberOfButtons print 1 + 1 + 1 every 2 seconds due to my invokerepeating but when I clic on one of my circles it does not do a - 1 on the variable it keeps going + 1 + 1 + 1 + 1 when it should do + 1 -1 + 1 + 1 + 1
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TheGame : MonoBehaviour { public Texture2D NormalCursor; public Vector2 hotspot = Vector2.zero; public CursorMode cursormode = CursorMode.Auto; public float GameBegin = 0; public GameObject Button; public float NumberOfButtons = 0; //buttons are the dot the player will have to clic public float Spawning = 0; public float Spawnn = 0;
private void Start()
{
Cursor.SetCursor(NormalCursor, hotspot, cursormode);
}
void Update()
{
if (GameBegin == 0)
{
NumberOfButtons = 0;
Spawnn = 0;
if (Input.GetKeyDown(KeyCode.E))
{
Spawning = 1;
Spawnn = 1;
if (Spawning == 1)
{
InvokeRepeating("Spawn", 2.0f, 2.0f);
Spawnn = 1;
}
print("A New Game Has Begun");
GameBegin = 1;
}
}
if (GameBegin == 1)
{
if (NumberOfButtons >= 7)
{
Spawning = 0;
print("GameOver");
GameBegin = 0;
//var ButtonClone = GameObject.Find("Button (Player)(Clone)"); //repair
//Destroy(ButtonClone); // repair
print("Game Has Restarted" + " " + "Press E To Continue");
}
}
}
void Spawn()
{
if (Spawnn == 1)
{
var position1 = new Vector3(Random.Range(-8.30f, 8.30f), Random.Range(-3.50f, 3.50f), 0f);
Instantiate(Button, position1, Quaternion.identity);
NumberOfButtons = NumberOfButtons + 1;
print(NumberOfButtons); //for testing purpose
}
}
void OnMouseUp()
{
NumberOfButtons = NumberOfButtons - 1;
print(NumberOfButtons);
Destroy(this.gameObject);
}
}
is this script attached to the ciercle you are clicking? or where is attached to?
Your answer
Follow this Question
Related Questions
[closed] problem with invokerepeating and public variable 1 Answer
Global Variables Refuse to Cooperate 1 Answer
Variable disappears in playmode? 1 Answer
Find Object with variable, not a name. 1 Answer
Can I make variables visible to other scripts without making them visible in the Inspector? 1 Answer