¿Cómo hacer que un objeto aparezca y desaparezca en diferentes momentos en el modo de juego Unity? [duplicate]
– UnityAssets3Free
bienvenido , me llamo juansito y esta vez os traigo
esta unity pregunta
Esta pregunta ya tiene respuestas aquí: ¿Cómo hacer que un objeto aparezca y desaparezca en diferentes momentos con Unity? [closed]
(2 respuestas) Cerrado hace 3 meses.
Quiero crear un objeto en Unity3D que aparezca y desaparezca aleatoriamente varias veces durante el modo de juego en ciertos momentos. El tiempo de ocurrencia del objeto debe ser determinado. Con el siguiente código, se muestra un cubo aleatorio y desaparece después de 3 segundos. Pero no debería ser visible al principio y luego aparecer varias veces.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Trigger: MonoBehaviour
public GameObject Object;
void Start()
StartCoroutine(ShowAndHide());
IEnumerator ShowAndHide()
Object.SetActive(true);
yield return new WaitForSeconds(3);
Object.SetActive(false);
1 respuesta 1
Necesitas crear un bucle tipo círculo para esto. Usa este código en tu rutina..
bool active = true; //if you want a stop this circle then false active value..
while(active)
Object.SetActive(!Object.activeSelf); // or activeInHierarchy
yield return new WaitForSeconds("yourTime");
Me di cuenta ahora al azar lol 🙂
yield return new WaitForSeconds(Random.Range(0f,'yourMaxValue'));
nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias
por hoy,espero que te halla servido