Problem with Images during Method-Call
Hi there,
I have an problem with the implementation of an image which shows how many lives the player has. I checked now for three days nearly everything but I can not find the error! So I hope you can help me.
In the child-element of the Canvas I installed the Image and it is working at the beginning correctly. But if the player gets hit it has to change into a new Image with the new "amount" of remaining lives. And this is also working right, but just for nearly 2 seconds. After that the image is changing back to the original.
I handle the different images via an array in a separated C#-Script for the UI-Manager.
public class UI_Manager : MonoBehaviour {
public Sprite[] lives;
public Image livesImageDisplay;
public GameObject titleScreen;
public Text scoretext;
private int score;
public void UpdateLives(int currentLives)
{
Debug.Log("currentLives: " + currentLives);
livesImageDisplay.sprite = lives[currentLives];
}
The Method UpdateLives is calling in the script of the player.
_lives--;
_uiManager.UpdateLives(_lives);
And after the direct call of the Damage-Method the Variable _lives is giving the right value to the Method in the UI-Manager. But if the Method is calling again (during the Update-Procedure), the value of _lives is 3 again.
And to get it completely confusing inside the Programm the Handler for the lives are working right. After three hits the player gets destroyed. Only the Image for the Lives isn't showing correctly.
I build that Script from an original script in a video-tutorial and checked it several times, but everything in the video and my Script is the same.
Does anybody of you have an idea how I can fix it?
Thank you really much in advance!
Greetings Benjamin
Your answer
Follow this Question
Related Questions
Canvas not filling up the whole screen in Unity 5 0 Answers
[SOLVED] Image is not visible in Panel (in game view) 0 Answers
How to offset a RectTransform? 0 Answers
Scaling an image sent to UI Image 0 Answers
Setting Sprite Rendered on UI 0 Answers