【发布时间】:2021-09-15 04:54:45
【问题描述】:
using UnityEngine;
using System;
public interface IAimPanel
{
public GameObject GetGameObject();
}
public class Target : MonoBehaviour, IAimPanel
{
public GameObject GetGameObject()
{
return gameObject;
}
}
public class Test : MonoBehaviour
{
public IAimPanel aimPanel;
private void Start()
{
aimPanel.GetGameObject().SetActive(true);
}
}
我希望能够通过 Unity C# 中的接口访问 gameObject,我已经在上面的代码中完成了,但我想要一个更优雅的实现。
类似的东西
private void Start()
{
aimPanel.gameObject.SetActive(true);
}
【问题讨论】: