Project
Beginner Gameplay Scripting
Scope and Access Modifiers
Tutorial
Beginner
10 Mins
Unity Technologies
Overview
You have completed 0% of this Tutorial.
1.
Scope and Access Modifiers
Summary
Understanding variable & function scope and accessibility.
This tutorial is included in the Beginner Scripting project.
Previous: Loops
Next: Awake and Start
Language
English
Recommended Unity Versions
4 and Above
1.
Scope and Access Modifiers

ScopeAndAccessModifiers

using UnityEngine; using System.Collections; public class ScopeAndAccessModifiers : MonoBehaviour { public int alpha = 5; private int beta = 0; private int gamma = 5; private AnotherClass myOtherClass; void Start () { alpha = 29; myOtherClass = new AnotherClass(); myOtherClass.FruitMachine(alpha, myOtherClass.apples); } void Example (int pens, int crayons) { int answer; answer = pens * crayons * alpha; Debug.Log(answer); } void Update () { Debug.Log("Alpha is set to: " + alpha); } }

AnotherClass

using UnityEngine; using System.Collections; public class AnotherClass { public int apples; public int bananas; private int stapler; private int sellotape; public void FruitMachine (int a, int b) { int answer; answer = a + b; Debug.Log("Fruit total: " + answer); } private void OfficeSort (int a, int b) { int answer; answer = a + b; Debug.Log("Office Supplies total: " + answer); } }

Woohoo! You nailed this tutorial.
Continue rocking your Beginner Gameplay Scripting project.
Next Step:
Awake and Start
Tutorial
Beginner
5 Mins
Unity Technologies