我有 2 個(gè) C# 類(lèi),其中一個(gè)有一個(gè)字符串委托,另一個(gè)為該委托訂閱一個(gè)函數(shù)。我的問(wèn)題是我想組合來(lái)自委托的兩個(gè)被調(diào)用的字符串函數(shù),而不是隨機(jī)選擇它們之間的返回值delgatesystem.cs:using System.Collections;using System.Collections.Generic;using UnityEngine;public class delegatesystem : MonoBehaviour {public delegate string MyDelegate();public static event MyDelegate MyEvent;string GameObjectsNames = "";void Update (){ if (Input.GetKeyDown(KeyCode.Space)) { if (MyEvent != null) { GameObjectsNames += MyEvent(); } } }}代表保存.cs:using System.Collections;using System.Collections.Generic;using UnityEngine;public class delegatesave : MonoBehaviour {void Start (){ delegatesystem.MyEvent += DelegateFunction;}string DelegateFunction(){ return gameObject.name;}}注意: delgatesave.cs 附加到 2 個(gè)游戲?qū)ο蟆?
- 1 回答
- 0 關(guān)注
- 149 瀏覽
添加回答
舉報(bào)
0/150
提交
取消