BASIC TELEPORTING QUEST: ‘Blink World Light’ - Solutions

Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.

For my blinking light I just had a secondary directional light left disabled with default values that i’d just flick on and off with a co-routine. (I was using the primary one to set a lighting tint to the darkness :stuck_out_tongue:

1 Like

I got stuck for a few hours on this one but it works now! finally!

My coroutine kept getting interrupted by the DeactivateObject(); bit so i used an invoke on that last bit.

I always thought that a coroutine made all other bits of the code stop/pause until the coroutine was done. I guess I was wrong there.

I ended up writing a Game Controller script and dropping it on the Gameplay object. This let me better control elements that weren’t specific to the teleporters. This let me adjust the last challenge so that I could designate the “First Teleporter” and make it glow without breaking up the prefab.

Specific to this challenge:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameController : MonoBehaviour {

    [SerializeField] Teleport FirstTeleportPad;
    [SerializeField] Light worldLight;
    [SerializeField] Light dimLight; // Ignore me, I want to be able to see the editor but make the game pitch black otherwise

    void Start()
    {
        FirstTeleportPad.Initialize();
        StartCoroutine ("BlinkWorldLight");
        dimLight.enabled = false; 
    }

    void Update()
    {
                
    }

    IEnumerator BlinkWorldLight()
    {
		while (true)
		{
            if (worldLight.enabled)
			{
                yield return new WaitForSeconds(1);
            }
			else
			{
                yield return new WaitForSeconds(3);
            }
            worldLight.enabled = !worldLight.enabled;
        }

    }
}

I activated the teleport script on both teleporters so the start() method is called. Each has one of the directional lights hooked up.
At the start I turn off all lights, then start the coroutines to blink them on for a couple of seconds (adjustable per SerializedField).

Here are the adjustments I made:

    [SerializeField] float worldLightBlinkTime = 5f;

    void Start() 
    {
        mainWorldLight.enabled = false;
        areaLight.enabled = false;
        StartCoroutine(nameof(BlinkWorldLight));
    }

    IEnumerator BlinkWorldLight()
    {
        mainWorldLight.enabled = true;
        yield return new WaitForSeconds(worldLightBlinkTime);
        mainWorldLight.enabled = false;
    }
    IEnumerator BlinkWorldLight(float timer)
    {
        mainWorldLight.enabled = true;
        yield return new WaitForSecondsRealtime(timer);
        mainWorldLight.enabled = false;

    }
2 Likes