Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- /*
- http://stackoverflow.com/questions/36809687/ui-canvas-image-with-ui-buttons
- */
- public class GameCanvas : MonoBehaviour
- {
- public Button pauseButton;
- public Button jumpButton;
- public Canvas pauseCanvas;
- void OnEnable()
- {
- //Register Button Events
- pauseButton.onClick.AddListener(() => buttonCallBack(pauseButton));
- jumpButton.onClick.AddListener(() => buttonCallBack(jumpButton));
- }
- private void buttonCallBack(Button buttonPressed)
- {
- //Pause Button Pressed
- if (buttonPressed == pauseButton)
- {
- //Pause Game here
- //Hide Game UI
- gameObject.SetActive(false);
- //Show Pause UI
- pauseCanvas.gameObject.SetActive(true);
- }
- //Jump Button Pressed
- if (buttonPressed == jumpButton)
- {
- jump();
- }
- }
- public void jump()
- {
- //Put your jump code here
- Debug.Log("Jumped");
- }
- void OnDisable()
- {
- //Un-Register Button Events
- pauseButton.onClick.RemoveAllListeners();
- jumpButton.onClick.RemoveAllListeners();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement