Hi, i have a code for shutting down light when button is pressed and lights are inside collider attached to player. But i cant find how to acess first object inside list ? How could I access random object in list ?
Thanks.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class LightsOff : MonoBehaviour {
private List<GameObject> ListOfLights = new List<GameObject> ();
private GameObject LLLight;
void OnTriggerEnter (Collider col){
if (col.gameObject.tag == "Player") {
if (gameObject.tag == "Light") {
ListOfLights.Add(LLLight);
LLLight = ListOfLights[0];
}
}
}
void OnTriggerExit (Collider col){
if (col.gameObject.tag == "Player") {
if (gameObject.tag == "Light") {
ListOfLights.Remove(LLLight);
}
}
}
void Update() {
if (Input.GetKeyDown("k")) {
ListOfLights[0].GetComponent<Light>().enabled = false;
}
}
}