UI Toggle with Key Combo

Unity3D Info
Post Reply
User avatar
nebadon
Site Admin
Posts: 107
Joined: Mon Feb 11, 2008 5:46 pm

Thu Mar 30, 2017 5:46 pm

Code: Select all

using UnityEngine;
using System.Collections;

public class MenuToggle : MonoBehaviour
{
    private Canvas CanvasObject; // Assign in inspector

    void Start()
    {
        CanvasObject = GetComponent<Canvas>();
    }

    void Update()
    {
        if ((Input.GetKey(KeyCode.LeftAlt)) && (Input.GetKeyUp(KeyCode.U)))
        {
            CanvasObject.enabled = !CanvasObject.enabled;
        }

        if ((Input.GetKey(KeyCode.RightAlt)) && (Input.GetKeyUp(KeyCode.U)))
        {
            CanvasObject.enabled = !CanvasObject.enabled;
        }

    }
}

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest