嗨,这段代码有什么问题?尝试在我的项目上添加mininap缩放。使用此代码。按钮导致我出现问题。这个问题有什么解决办法吗?
public class UIMinimap : MonoBehaviour
{
public GameObject panel;
public float zoomMin = 5;
public float zoomMax = 50;
public float zoomStepSize = 5;
// public Text sceneText;
public Button plusButton;
public Button minusButton;
public Camera minimapCamera;
void Start()
{
plusButton.onClick.SetListener(() => {
minimapCamera.orthographicSize =
Mathf.Max(minimapCamera.orthographicSize - zoomStepSize, zoomMin);
});
minusButton.onClick.SetListener(() => {
minimapCamera.orthographicSize =
Mathf.Min(minimapCamera.orthographicSize + zoomStepSize, zoomMax);
});
}
}
答案 0 :(得分:2)
我不知道您从何处SetListener
,正确的语法是AddListener
,如API所示:
plusButton.onClick.AddListener(() => {
minimapCamera.orthographicSize = Mathf.Max(minimapCamera.orthographicSize - zoomStepSize, zoomMin);
});