Check out a free preview of the full Game Development with Unity for Web Developers course

The "Score Exercise" Lesson is part of the full, Game Development with Unity for Web Developers course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to write a method that resets the score value and another method that increments the score value.


Transcript from the "Score Exercise" Lesson

>> Now that we've learned a little bit about coding in unity, I have an exercise for us. So, we need to make a new component called score. Score is going to be a simple component, that will keep track of each player's individual score. So this will be applied to player a game object, and then we also will create an opponent game object later on that it will also get applied to.

And later will actually update this script, so that it can interact with UI. So here's kinda the starting script that you should create for this exercise and we'll use a C# property to store the score as an integer type, so up here at the top we have, what's called a property.

And that way the value can be accessed publicly, but only modified via this script. So other components, other scripts will be able to access this score value. But it can only be set within the script because it's a property with a public getter, but a private setter. So the exercise is to write a method to reset that score value, and then another method to increment the value.

So we want to increment the value by one and when it gets reset we wanna set it back to zero. So I'll give everyone a little bit of time to write out this script. And, I guess when we are done, I can go over the solution.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now