Noticias

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

Ayuda en mi script

Iniciado por Nontre, Marzo 11, 2016, 08:56:21 PM

Tema anterior - Siguiente tema
Hola buenas quería saber si me podrían ayudar a corregir este script:#pragma strict
private var construccion = false;
var Cubo : GameObject;
var Lado = 0;
private var Puedo = false;
/*
function Start()
{

}
*/
function Update()
{
  if(Input.GetKeyDown(KeyCode.Mouse0))
  {
    if(Puedo)
    {
      Construir();
    }
  }
 
  if(Input.GetKeyDown(KeyCode.Mouse1))
  {
    if(Puedo)
    {
      Destruir();
    }
  }
  if(Input.GetKeyDown(KeyCode.Tab))
  {
     construccion = true;
  }
  else
  {
     construccion = false;
  }
}
/*
function OnMouseDown()
{
  Construir();
}
*/
function OnMouseEnter()
{
if(construccion)
   {
      {
           Puedo = false;      
      }
   }
}
function OnMouseEnter()
{
if construccion = true
{
   Puedo = true:
}
}
function OnMouseExit()
{
        Puedo = false;
}

function Construir()
{
 // var Posicion : Vector3 = Cubo.transform.position;
 // var Rotacion : Vector3 = Cubo.tranform.rotation;
  //Arriba
  if(Lado == 1)
  {
    var Clon1 = Instantiate(Cubo, Cubo.transform.position, Cubo.transform.rotation);
    Clon1.transform.position.y += 1;
  }
  //Izquierda
  if(Lado == 2)
  {
    var Clon2 = Instantiate(Cubo, Cubo.transform.position, Cubo.transform.rotation);
    Clon2.transform.position.x -= 1;
  }
  //Derecha
  if(Lado == 3)
  {
    var Clon3 = Instantiate(Cubo, Cubo.transform.position, Cubo.transform.rotation);
    Clon3.transform.position.x += 1;
  }
  //Adelante
  if(Lado == 4)
  {
    var Clon4 = Instantiate(Cubo, Cubo.transform.position, Cubo.transform.rotation);
    Clon4.transform.position.z += 1;
  }
  //Atras
  if(Lado == 5)
  {
    var Clon5 = Instantiate(Cubo, Cubo.transform.position, Cubo.transform.rotation);
    Clon5.transform.position.z -= 1;
  }
  //Abajo
  if(Lado == 6)
  {
    var Clon6 = Instantiate(Cubo, Cubo.transform.position, Cubo.transform.rotation);
    Clon6.transform.position.y -= 1;
  }
}

function Destruir()
{
  Destroy(Cubo.gameObject);
}El script no es mío lo saqué de un vídeo de YouTube y lo que pretendía era crear una variable "construccion" para alternar entre si la variable "Puedo" sea (true o false al pulsar la tecla Tab) pero me da error. No tengo esperiencia en programación...

¿lo que quieres es que al presionar tabulador la variable cambie su valor? de true a false y visceversa?


puedes hacer algo como estobool Var;
    void Update(){
        if (Input.GetKey(KeyCode.Tab)) {
            Var = !Var;
        }
    }donde en update estas esperando que se presione la tecla tab y al presionarse canbias el valor que tiene tu variable a lo opuesto.




Etiquetas: