unity 获取继承于MonoBehaviour的所有脚本,并提取出需要的实例

	MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];

		foreach(MonoBehaviour monoScript in monoScripts)
		{
			if((monoScript is InteractionManager) && monoScript.enabled)
			{
				InteractionManager manager = (InteractionManager)monoScript;

				if (manager.playerIndex == playerIndex) 
				{
					return manager;
				}
			}
		}

 

你可能感兴趣的:(unity)