- Home /
[C#] Activating set amount of objects to spawn another object?
So in my game I have a light switch and a torch with a flame. The flame is the game object and the switch turns it on and off. I want to include a puzzle in my game where the player will find a room with a set of lights on and off.
(Example: 5 lights in a row. 1st light is on, 2nd is off, 3rd and 4th on, 5th off)
In the other room the player will find a set of lights off with the light switches underneath each torch to activate the torches.
The theory is once the player activates the amount of lights that were in the other room by memory, it would spawn a key in the room where the player was turning the lights on and off. I'm not sure how I would go about doing this at all. I've thought it over a million times and can't think about it. I really could use some help!
My script for my light switch:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightSwitch : MonoBehaviour
{
public GameObject light;
private bool on = false;
private void Start()
{
light.SetActive(on);
}
// Use this for initialization
void OnTriggerStay(Collider player)
{
if (player.tag == "Player" && Input.GetKeyDown(KeyCode.E) && !on)
{
light.SetActive(true);
on = true;
Debug.Log("Light On");
}
else if (player.tag == "Player" && Input.GetKeyDown(KeyCode.E) && on)
{
light.SetActive(false);
on = false;
Debug.Log("Light Off");
}
}
}
Your answer