Day 10: Grasping At The Reins
--
Grasping at the reigns of this method and logic sequence so that I can properly use it in the future, and truly understand what I am doing.
Today was a bit of an extension of yesterday, but even more, am I trying to understand the method with the parameters to understand how the logic sequences made sense to, not just make the scores work correctly, but also the lives (the damage the player takes) and how it communicates with the other scripts.
These are the two lines that had my head trying to decipher and understand just how it is working behind the coding.
Here towards the bottom of the UIManager script is where I was struggling to understand why it was working.
public void UpdateScore(int playerScore)
{ _scoreText.text = “Score “ + playerScore.ToString();}
From my growing understanding, this is a method with a parameter that says that the scoreText that was set up as a text component in the UIManager script (which = the literal text “Score: “ + 0 when the script first initializes (void start)) then grabs the playerScore from the Player script, because that script is communicating with the UIManager script giving it the number.
The next method with a parameter that I was trying to understand, with much difficulty I might add was:
public void UpdateLives(int currentLives)
{_LivesImg.sprite = _livesSprites[currentLives];}
This method was to take the _LivesImg.sprite and assign it to an array (_liveSprites). Then these lives, numbered 0 to 3 (since the player is assigned 3 lives), will then show the corresponding sprite of the lives of the Player. This way as the _LiveImg.sprite changes (and is assigned to that at the same time as when the “private Image _LivesImg”) with the number of lives the Player has.
This really had my brain wrapped. And honestly, it still hurts my head trying to figure out and learn the proper words to use to make the right sequences happen.
But what can I say, I want to really know what I’m doing so that I can be able to build this game again, but without a tutorial, just from looking up the words needed, or are associated with the right functions. I’m not 100% confident in my understanding up to this point yet. But day by day, I’m working towards my goal of learning C# so that I can be knowledgeable and efficient in my coding.