1
votes

Hi what the wrong with this code? try to add mininap zoom on my project. using this code. The Button is causing me a problem. any solution for this problem?

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);

        });
    }
}
1

1 Answers

2
votes

I don't know where you've gotten SetListener from, the correct syntax is AddListener, as seen in the API:

plusButton.onClick.AddListener(() => {
  minimapCamera.orthographicSize = Mathf.Max(minimapCamera.orthographicSize - zoomStepSize, zoomMin);
});