Noticias

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

OntrigguerEnter

Iniciado por marboxrem, Octubre 22, 2015, 06:48:11 PM

Tema anterior - Siguiente tema
Octubre 22, 2015, 06:48:11 PM Ultima modificación: Octubre 22, 2015, 06:48:37 PM por marboxrem
Hola, tengo un problema, yo tengo este codigo que cada 4 segundos activa de forma aleatoria(segun el numero que salga en el Random.Range) un cubo, lo que quisiera saber es como puedo hacer para activar y desactivar este escript por OntriggerEnter
      using UnityEngine;
using System.Collections;public class Activar1 : MonoBehaviour {
    public GameObject c1;
    public GameObject c2;
    public GameObject c3;
    float timeStart;
    public float tiempo = 4f;
    int n;    
    void Start()
    {
        timeStart = Time.time;    }    void OntriggerEnter(Collider other){
        if (other.tag == "Player") {
            LlmarCubos ();
        }
    }    void LlmarCubos(){
        if (Time.time - timeStart > tiempo) {
            timeStart = Time.time;
            n = Random.Range (1, 5);
            print(n);
        }        if (n == 1) {
            c1.SetActive (true);
        } else {
            c1.SetActive (false);
        }
        if (n == 2) {
            c2.SetActive (true);
        } else {
            c2.SetActive (false);
        }
        if (n == 3) {
            c3.SetActive (true);
        } else {
            c3.SetActive (false);
        }
    
    
    }
        }

creas una variable bool OnTriggerEnter () {mivariblebool = !mivariablebool; //esto haría que si está en true lo convierte en false y viceversa.}Update () {if(mivariablebool == true){LlmarCubos();}}

Etiquetas: