Game Development Reference
In-Depth Information
27 //Call event
28 NumberChanged();
29 }
30 }
31 }
32 //------------------------------------------------------
33 //Internal reference a number between 1-10
34 private int iMyNumber = 0;
35 //------------------------------------------------------
36 // Use this for initialization
37 void Start ()
38 {
39 //Set MyNumber
40 MyNumber = 11; //Will fail because number is > 10
41
42 //Set MyNumber
43 MyNumber = 7; //Will succeed because number is between 1-10
44 }
45 //------------------------------------------------------
46 //Event called when iMyNumber is changed
47 void NumberChanged()
48 {
49 Debug.Log("Variable iMyNumber changed to : " +
iMyNumber.ToString());
50 }
51 //------------------------------------------------------
52 }
53 //------------------------------------------------------
The following are the comments for code sample 1-15:
Line 10 : A public integer property is declared. This property is not an
independent variable but simply a wrapper and accessor interface for
the private variable iMyNumber , declared in line 34.
Line 13 : When MyNumber is used or referenced, the internal get function
is called.
Line 14 : When MyNumber is assigned a value, the internal set function is called.
Line 25 : The set function features an implicit argument value that represents
the value to be assigned.
Line 28 : The event NumberChanged is called when the iMyNumber variable is
assigned a value.
 
Search WWH ::




Custom Search