Unity Spain

Post Antiguos => General (Antiguo) => Mensaje iniciado por: marboxrem en Octubre 22, 2015, 06:48:11 PM

Título: OntrigguerEnter
Publicado por: marboxrem en Octubre 22, 2015, 06:48:11 PM
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);
        }
    
    
    }
        }
Título: OntrigguerEnter
Publicado por: leocub58 en Octubre 22, 2015, 07:44:04 PM
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();}}