Muy buenas! Sabeis como puedo conseguir que este código no se repita??? que una vez ejecutado ó bien no se pueda volver a ejecutar o bien haga la ejecución al contrario.
un saludo gracias !!!
using UnityEngine;
using System.Collections;
public class dooControl : MonoBehaviour {
public float speed;
public float angle;
public Vector3 direction;
void Start() {
angle = transform.eulerAngles.y;
}
void Update() {
if (Mathf.Round(transform.eulerAngles.y) != angle) {
transform.Rotate(direction * speed);
}
if (Input.GetKeyDown(KeyCode.0)) {
angle = 90;
direction = Vector3.up;
}
if (Input.GetKeyDown(KeyCode.C)) {
angle = 0;
direction = Vector3.up;
}
}
}
Perdón ese code no es, es este:
using UnityEngine;
using System.Collections;
public class DoorController : MonoBehaviour {
public GameObject Door;
public bool doorIsOpening;
void Update () {
if (doorIsOpening == true) {
Door.transform.Translate (Vector3.up * Time.deltaTime * 5);
}
if (Door.transform.position.z > 4f) {
doorIsOpening = false;
}
}
void OnMouseDown(){
doorIsOpening = true;
}
}
Hola!! En estos casos se suele realizar una función, esta función mueve la puerta
si está cerrada
o si está abierta;
bool abierta = false;
bool moviendose = false;
void MoverPuerta ()
{
if(abierta == true)
{
Door.transform.Translate (Vector3.down * Time.deltaTime * 5);
if(Door.transform.position.z < 0f)
{
moviendose = false;
abierta = false;
}
}
else
{
Door.transform.Translate (Vector3.up * Time.deltaTime * 5);
if(Door.transform.position.z > 4f)
{
moviendose = false;
abierta = true;
}
}
}
Como ves,
si abierta es true entonces
translada la puerta hacia abajo y
si la posición Z es menor que 0 entonces
deja de moverse, cuando
abierta es false entra en la otra llave.