protected的问题 求大佬解释一下
unity3d吧
全部回复
仅看楼主
level 6
a5417201 楼主
代码
protected UnityEvent leftClick;
protected void AddAllEvent(bool isLeft=false,bool isRight=false,bool isMiddle=false)
{
if (isLeft)
leftClick.AddListener(new UnityAction(ButtonLeftClick));
if (isRight)
rightClick.AddListener(new UnityAction(ButtonRightClick));
if (isMiddle)
middleClick.AddListener(new UnityAction(ButtonMiddleClick));
}
调用
base.Awake();
if (transform.name!= "Button")
{
AddAllEvent(true);
}
子类调用的结果是报空
我把声明的leftClick 改成public修饰后 是可以正常运行的 但这里有什么原理吗?求解答
2020年06月22日 12点06分 1
level 6
a5417201 楼主
[乖]
2020年06月22日 12点06分 2
level 6
不懂,protected子类调用应该不会报空把...
2020年06月22日 13点06分 3
level 6
a5417201 楼主
委托添加的方法ButtonLeftClick也是用protected修饰 但就算改成public也会报空 估计就是这个 leftClick有问题[乖]
2020年06月23日 02点06分 4
1