- Home /
How to display an object for just few seconds repeatedly in a scene?
I am making a VR video on the working of GNSS Satellite. My scene has an Earth and a satellite which is orbiting around the Earth. I want to show signal transmission from and to the satellite with the help of arrows. But these arrows ( one pointing from satellite to earth and other pointing from earth to satellite) should be visible only for the amount of time the satellite crosses their position. How can I do that? Kindly help please
Answer by Llama_w_2Ls · Jan 30, 2021 at 12:31 PM
A simpler way is using a coroutine. For example:
public float TimeAmount;
public GameObject arrow;
void Start()
{
StartCoroutine(ToggleArrow(TimeAmount));
}
IEnumerator ToggleArrow(float delay)
{
while (true)
{
yield return new WaitForSeconds(delay);
arrow.SetActive(true);
yield return new WaitForSeconds(delay);
arrow.SetActive(false);
}
}
Heyy, thanks for this answer.. with this my arrow gets disappeared but how do I show it again? Suppose for now I have kept the time limit as 2 seconds. So it does go away in 2 seconds but I want it to come again and then go again and so on. It should blink
I thought that's what my script does. It waits two seconds, sets the arrow object to active, waits two seconds, sets it to inactive, and repeats infinitely. Possibly you implemented it incorrectly?
I dont find it implementing incorrectly.. my arrow just got disappeared after 2 seconds (which I mentioned) but it didnt re appear again
Answer by MathijnG · Jan 29, 2021 at 03:45 PM
For me normally the easiest way would be to use Time.deltaTime. See here:
float TimeAmount;
float currentTime;
GameObject arrow;
private void Start()
{
currentTime = TimeAmount;
}
private void Update()
{
currentTime -= Time.DeltaTime;
if (currentTime <= 0)
{
if (arrow.activeSelf)
{
arrow.SetActive(false);
}
else
{
arrow.SetActive(true);
}
currentTime = TimeAmount;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613024201im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can you download unity editor onto a USB device? 2 Answers
Space ship controls locking into place 1 Answer
Box Collider bounce causing rigidbody to change rotation -1 Answers
3d space scene tutorial? 0 Answers
How to export on spacescape 0 Answers