- Home /
I have 4 cubes and when they enter four boxcolliders the boxcolliders set a cube active if all for cubes are set active then this script will set a key active C# (Not Working)
this is my script
using UnityEngine;
using System.Collections;
public class ColorDetector : MonoBehaviour
{
public GameObject Key;
void OnTriggerEnter (Collider Keyz)
{
if (Key.gameObject.tag == "Yellow")
{
if (Key.gameObject.tag == "Blue")
{
if (Key.gameObject.tag == "Red")
{
if (Key.gameObject.tag == "Green")
{
Debug.Log ("IT Worked");
Key.SetActive (true);
}
}
}
}
}
}
Answer by jman12EX · Jan 27, 2018 at 11:34 PM
@rapinnz there i know i answered your other one but this has the part where if all are triggered
public bool havekeyBlue = false;
public bool havekeyGreen = false;
public bool havekeyRed = false;
public bool havekeyYellow = false;
public GameObject me;
void Start()
{
}
void Update()
{
if(havekeyBlue==true && havekeyGreen==true && havekeyRed==true && havekeyYellow==true)
{
//add what you want to happen here when you have all the keys
}
}
private void OnTriggerEnter(Collider collider)
{
if (collider.CompareTag("BlueKey"))
{
havekeyBlue = true;
}
if (collider.CompareTag("GreenKEy"))
{
havekeyGreen = true;
}
if (collider.CompareTag("RedKey"))
{
havekeyRed = true;
}
if (collider.CompareTag("YellowKey"))
{
havekeyYellow = true;
}
}
thanks but i dont want the key to change color i want the trigger to detect that all four cubes are in the trigger then set the key to active.
that is what that dose you give them the tags "yellowkey" and when you go inside the trigger of that object you will then set it to true put it on your script and it will work
Answer by KittenSnipes · Jan 21, 2018 at 03:07 AM
@rapinnz Change This:
using UnityEngine;
using System.Collections;
public class ColorDetector : MonoBehaviour
{
public GameObject Key;
void OnTriggerEnter (Collider Keyz)
{
if (Key.gameObject.tag == "Yellow")
{
if (Key.gameObject.tag == "Blue")
{
if (Key.gameObject.tag == "Red")
{
if (Key.gameObject.tag == "Green")
{
Debug.Log ("IT Worked");
Key.SetActive (true);
}
}
}
}
}
}
To this:
using UnityEngine;
using System.Collections;
public class ColorDetector : MonoBehaviour
{
public GameObject Key;
void OnTriggerEnter (Collider Keyz)
{
if (Keyz.gameObject.tag == "Yellow")
{
if (Keyz.gameObject.tag == "Blue")
{
if (Keyz.gameObject.tag == "Red")
{
if (Keyz.gameObject.tag == "Green")
{
Debug.Log ("IT Worked");
Key.SetActive (true);
}
}
}
}
}
}
All I did was add a 'z' to each part. Stuff like this can make a huge change.
Im too sure all i know is that it dosent even show the debug text
Your answer
![](https://koobas.hobune.stream/wayback/20220612150931im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Door open script opens all the doors in the scene 3 Answers
Make an object a certain distance from me. 2 Answers
iterate through two lists element by element 1 Answer
my prefab clone object are falling from ground in y direction? 0 Answers
How to make a gun autoaim on targets under the reticule? 0 Answers