Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.
I wasn’t really sure how to implement this one, I guess we were supposed to use the area lights attached to the prefab? Instead I decided to just make the individual teleporter material emissive, I figure the glow in the dark should lead players in the right direction
That is a cool solution. I did end up adding in some of my own lights for this one and rearranging some of the pre-existing lights in the hierarchy.
Great thinking on that one and it looks good too!
Kurt
I used the area light inside the house
if(areaLight.name == "Area Light (1)")
{
areaLight.GetComponent<Light>().enabled = true;
}
I added a new field nextTeleport
to the top of the Teleport.cs Script:
[SerializeField] Transform nextTeleport;
So anyone making the maps can decide for themselves where the Area Light
inside the Elements
will be at. I deactivated the Area Light by default and set my method to this:
void IlluminateArea()
{
if (!nextTeleport) return;
areaLight.enabled = true;
areaLight.transform.position = nextTeleport.position;
}
Good thinking!
I was a bit confused about this instruction at first. It’s meant to guide the player around the level, but I couldn’t stop thinking about Vortegaunts teleporting into a room. I decided to make the green light an active part of the teleportation process by slapping a script on the gameplay lights that run a coroutine to turn the lights on and off:
public class LightControl : MonoBehaviour
{
/// <summary>
/// Initialize the area light blink routine.
/// </summary>
public void Illuminate()
{
StartCoroutine(nameof(LightRoutine));
}
/// <summary>
/// Brighten teleporter area lights for 1.2 seconds.
/// </summary>
/// <returns>Interval yield instruction.</returns>
IEnumerator LightRoutine()
{
GetComponent<Light>().intensity = 5f;
yield return new WaitForSeconds(1.2f);
GetComponent<Light>().intensity = 0;
}
}
This way, in the Teleport.cs
script, I can add a serialized unity event to broadcast that it needs to run that coroutine whenever OnTrigger happens.
public class Teleport : MonoBehaviour
{
[SerializeField] UnityEvent onTeleport;
/// <summary>
/// Triggerd when the player walks onto this object.
/// </summary>
/// <param name="other">The player's collider</param>
void OnTriggerEnter(Collider other)
{
IlluminateArea();
}
/// <summary>
/// Invoke the area light blinking event.
/// </summary>
void IlluminateArea()
{
onTeleport.Invoke();
}
}
Set the green light as the listener.
void DeactivateObject()
{
GetComponent<BoxCollider>().isTrigger = false;
if (areaLight != null )
{
areaLight.GetComponent<Light>().enabled = false;
}
}
void IlluminateArea()
{
if (nextLight != null)
{
nextLight.GetComponent<Light>().enabled = true;
}
}
also
[SerializeField] Light nextLight;
I’ve created a SerializeField variable called “nextTelepor” to indicate wich is going to be the next one.
Each teleport has a spotlight inside, so I get that component and enabled / disables the light
Code:
[SerializeField] GameObject nextTeleport;
void DeactivateObject()
{
this.gameObject.GetComponent<Teleport>().teleportTarget = null;
GetComponentInChildren<Light>().enabled = false;
}
void IlluminateArea()
{
if (nextTeleport)
{
nextTeleport.GetComponentInChildren<Light>().enabled = true;
}
}