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
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;
}
}
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);
}
}