Game Development Reference
In-Depth Information
02 using System.Collections;
03
04 public class MyScriptFile : MonoBehaviour
05 {
06 //Private variable for score
07 //Accessible only within this class
08 private int Score = 0;
09
10 // Use this for initialization
11 void Start ()
12 {
13 //Call update score
14 UpdateScore(5, false); //Add five points
15 UpdateScore (10, false); //Add ten points
16 int CurrentScore = UpdateScore (15, false); //Add fifteen
points and store result
17
18 //Now double score
19 UpdateScore(CurrentScore);
20 }
21
22 // Update is called once per frame
23 void Update ()
24 {
25 }
26
27 //Update game score
28 public int UpdateScore (int AmountToAdd, bool
PrintToConsole = true)
29 {
30 //Add points to score
31 Score += AmountToAdd;
32
33 //Should we print to console?
34 if(PrintToConsole){Debug.Log ("Score is: " +
Score.ToString());}
35
 
Search WWH ::




Custom Search