- Home /
Array of colliders/triggers
Hello, I am in the process of making a game where there are 10 beds lined up with lights above each, for every turn one light turns red and the player must walk over to it and press a button. Once the input is received the light turns off and the next turn starts where a new random light will turn on.
My problem is that I'm not sure how to get the collider for that particular bed.
So far, I have an int value from 0-9 that then gets the light and bed attached to that spot from the arrays. The light works perfect, but I'm not sure how to go about working with the bed.
Here is my code so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bed : MonoBehaviour {
public static Light light;
public static GameObject bedNum;
int whichBed;
public GameObject[] beds = null;
public Light[] lights = null;
public static bool help = false;
public static bool bedClick = false;
System.Random rnd = new System.Random();
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Turn.newTurn > Turn.turn) {
whichBed = rnd.Next(0,9);
light = lights[whichBed];
bedNum = beds[whichBed];
light.color = Color.red;
Turn.turn = Turn.newTurn;
}
}
}
And:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collide : MonoBehaviour {
public static GameObject bed = Bed.bedNum;
void OnTriggerEnter (Collider col){
if (col.gameObject.name == "bed") {
Debug.Log ("Enter");
}
if (Bed.help == true) {
}
}
}
Your answer
Follow this Question
Related Questions
Translate.transform problems (collision/Rigibody) 0 Answers
How can I check if an instantiated object collides with another instantiated object? 1 Answer
Reference GameObject from Bounds.Contain 1 Answer
NullReferenceException when trying to get Collider2D's parent gameObject 1 Answer
C# Unity , How I Can Increase speed of game-object in Y axis in (spawn wave) pair time unit ?? 0 Answers