我有 2 个 C# 类,其中一个有一个字符串委托,另一个为该委托订阅一个函数。我的问题是我想组合来自委托的两个被调用的字符串函数,而不是随机选择它们之间的返回值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 个游戏对象。
1 回答
- 1 回答
- 0 关注
- 136 浏览
添加回答
举报
0/150
提交
取消