I have 2 separate scripts, one with the value of how many lives the player has left and spawn the player when they trigger it, the other is attached to the GUI hearts I have in my canvas to remove hearts when the player dies. My problem is this, I cant seem to get the GUI script to read how many lives I have left, when the integer goes down to 2 the hearts stay 3. I do not know whether this is a problem with my scripts, but here they are just in case their the cause:
PlayerRespawn
public int LevelNumber;
public GameObject player;
public Transform playerSpawnPoint;
public int LIVES = 3;
void OnCollisionEnter2D(Collision2D target)
{
if (target.gameObject.tag == "Player")
LIVES -= 1;
{
switch (LIVES)
{
case 3:
target.transform.position = playerSpawnPoint.position;
break;
case 2:
target.transform.position = playerSpawnPoint.position;
break;
case 1:
target.transform.position = playerSpawnPoint.position;
break;
case 0:
Application.LoadLevel(LevelNumber);
break;
}
}
}
}
HeartControl
public int LIVES;
public Texture2D Heartlife1;
public Texture2D Heartlife2;
public Texture2D Heartlife3;
void Update ()
{
Boundary.PlayerRespawn.LIVES ();
switch(LIVES)
{
case 3:
guiTexture.texture = Heartlife3;
break;
case 2:
guiTexture.texture = Heartlife2;
break;
case 1:
guiTexture.texture = Heartlife1;
break;
}
}
}