我有一个GameObject作为玩家上面有一个script叫做PlayerController.cs
这个GameObject下面有放两个角色GameObject分别都带有一个script,RoleA.cs与RoleB.cs
游戏中玩家只能同时使用一个角色
我想要在RoleA与RoleB中去呼叫PlayerController.cs的函式与变数
请问下列哪一种方法比较好
1. 将PlayerController中,要呼叫的的函式与变数设为static,直接给RoleA与RoleB调用
2. 在RoleA与RoleB中宣告类别 public PlayerController player,从interseptor上做对应
3. 在RoleA与RoleB中宣告类别 private PlayerController player,透过GetComponet做对应
4. 要用的时候寻找玩家的GameObject,发送sendmessage调用
这个GameObject下面有放两个角色GameObject分别都带有一个script,RoleA.cs与RoleB.cs
游戏中玩家只能同时使用一个角色
我想要在RoleA与RoleB中去呼叫PlayerController.cs的函式与变数
请问下列哪一种方法比较好
1. 将PlayerController中,要呼叫的的函式与变数设为static,直接给RoleA与RoleB调用
2. 在RoleA与RoleB中宣告类别 public PlayerController player,从interseptor上做对应
3. 在RoleA与RoleB中宣告类别 private PlayerController player,透过GetComponet做对应
4. 要用的时候寻找玩家的GameObject,发送sendmessage调用