K
K
Kirill Kichigin2017-03-31 14:56:22
Unity
Kirill Kichigin, 2017-03-31 14:56:22

When you press the same button again on the keyboard, a different action occurs. How to do?

I'm doing inventory. And I need that when I press the TAB button again, the inventory closes, not opens 5b7f17f7969c4effaae31574f42440be.png. How to do?
script:=

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InventoryOpen : MonoBehaviour {
  public GameObject Inventory;

  // Use this for initialization
  void Start () {
    
  }
  
  // Update is called once per frame
  void Update () {
    if( Input.GetKeyDown( KeyCode.Tab ) )
      Inventory.transform.position = new Vector3(240, 173, 0);
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2017-03-31
@KiR_Ka

If open, close. If closed, open. How to check the current state - come up with it yourself.

G
GreatRash, 2017-03-31
@GreatRash

// ...

public class InventoryOpen : MonoBehaviour {
  private bool open = false;

  void Update() {
    if (Input.GetKeyDown(KeyCode.Tab)) {
      open = !open;

      if (open) {
        Debug.Log('open');
      } else {
        Debug.Log('close');
      }
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question