Okay, imagine this:
There’s a prefab, and it’s a cube. There’s a bunch of these cubes on scene. The prefabs have a script attached to them with a boolean - the boolean is false. I have written a poetic code that make the boolean true if you click at the cube. The problem is: the boolean changes for all prefab cubes, and not just the one I clicked.
How can I make an “individual” boolean for these prefabs? It has to be possible. I know that many makes their enemies into prefabs, and their health changes individually, so a prefab is therefore capable of individuality. Or am I wrong? Thanks in advance for reading
It’s not static, and I’ve tried booleans, ints, both private and public. Right now it looks like this (I changed the boolean previously mentioned to an int, just to see if anything changed):
public int CanIMove = 0;
This is how I click:
private void Update()
{
// When you click the box it will be allowed to move.
if(Input.GetMouseButtonDown (0)){
CanIMove=1;
}
// If you click control, the box will not be able to move.
if(Input.GetKeyUp(KeyCode.LeftControl))
{
CanIMove = 0;
}
// If you are allowed to move, the move code below is activated.
if(CanIMove == 1){
// Bunch of move code.
}