Game Development Reference
In-Depth Information
44 // Update is called once per frame
45 void Update ()
46 {
47 //Calculate position on-screen
48 Vector3 FinalPosition = new Vector3(HorzAlign == HALIGN.left ? 0.0f : Screen.width,
49 VertAlign == VALIGN.top ? 0.0f : -Screen.height,
50 ThisTransform.localPosition.z);
51
52 //Offset with padding
53 FinalPosition = new Vector3(FinalPosition.x + (Padding.LeftPadding *
Screen.width) - (Padding.RightPadding * Screen.width), FinalPosition.y -
(Padding.TopPadding * Screen.height) + (Padding.BottomPadding * Screen.height),
FinalPosition.z);
54
55 //Convert to pixel scale
56 FinalPosition = new Vector3(FinalPosition.x / GUICamera.PixelToWorldScale,
FinalPosition.y / GUICamera.PixelToWorldScale, FinalPosition.z);
57
58 //Update position
59 ThisTransform.localPosition = FinalPosition;
60 }
61 //------------------------------------------------
62 }
63 //------------------------------------------------
Line 08. Here, the [System.Serializable] directive is used to declare the
class PixelPadding to be a serializable class. This means that any instances
of the class, and its members, will be accessible and editable via the Object
Inspector in the Unity Editor. This directive is significant for member variable
Padding , declared at line 18. This member is viewable and editable in the Object
Inspector (see Figure 8-3 ).
Figure 8-3. Starting to create a menu object . . .
Search WWH ::




Custom Search