How to make the weapon disappear on the same key that makes it appear in UNITY

1
   using UnityEngine;
   using System.Collections;

   public class SelecteArma : MonoBehaviour {


    public bool Equipamento = true;

    void Start () {
    }


    void Update () {
    if (Input.GetKeyDown ("1")) {
    selecionarArma (0);
    }

    if (Input.GetKeyDown ("2")) {
    selecionarArma (1);
    }
    }


    public void selecionarArma (int index){
    for (var i = 0; i<transform.childCount; i++) {
    if (i == index)
    transform.GetChild (i).gameObject.SetActiveRecursively (false);
    else
    transform.GetChild (i).gameObject.SetActiveRecursively (true);
    }
    }
    }
    
asked by anonymous 20.05.2015 / 16:12

1 answer

3

You can simply assign a negation to a bool variable, and use that to hide and display the weapon.

var muda = true;

//atribui o valor contrário ao actual, se for true passa para false e vice-versa
muda = !muda; 
    
16.06.2015 / 20:02