Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

como hacer desaparecer un objeto pulsando un boton

Iniciado por berserker, Diciembre 09, 2015, 08:04:00 PM

Tema anterior - Siguiente tema
hola lo que busco es simple , pulsando un GUI botón  que aparezca y desaparezca un gameobjet como un cubo etc.este código me sirve para conseguirlo pulsando un botón del teclado "q", pero quiero conseguirlo con un gui botón de pantalla:using UnityEngine;
using System.Collections;public class EnableDisableGameObject : MonoBehaviour
{
 public GameObject cubo;
 public void Start()
 {
  cubo = GameObject.Find("Cube"); } public void Update()
 {
  if(Input.GetKeyDown("q"))cubo.SetActive(false);     if(Input.GetKeyDown("w"))cubo.SetActive(true);}} tendré que asignarle el script a el botón UI ,pero no se que función es la que debo usar para conseguirlo.os dejo el video de donde  he sacado el código: https://www.youtube.com/watch?v=2USGWNS3dcU     un saludo y gracias.

Diciembre 10, 2015, 04:34:46 AM #1 Ultima modificación: Diciembre 10, 2015, 04:40:23 AM por brok
using UnityEngine;
using System.Collections;

public class des : MonoBehaviour {
    public GameObject cubo;
    // Use this for initialization
   

    // Update is called once per frame
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            cubo.gameObject.SetActive(false);
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            cubo.gameObject.SetActive(true);
        }

    }
}
 

Etiquetas: