教程地址(观看视频需翻墙):
https://unity3d.com/cn/learn/tutorials/topics/scripting/scope-and-access-modifiers?playlist=17117
教程代码实例:(简化版)
ScopeAndAccessModifiers
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class access : MonoBehaviour {
public int alpha = 5; //公有变量,class外部可访问
private int beta = 0; //只能在class里面用
private otherAccess myOtherclass;
// Use this for initialization
void Start ()
{
alpha = 29;
myOtherclass = new otherAccess();//新定义一个instance class
myOtherclass .FruitMachine (alpha ,myOtherclass .apples );
//这里只能调用otherAccess的共有函数,所带参数可以是自己的变量,