Using variables from colliders across scripts

Hey, I’m really struggling with a good way to do this, mainly passing the variables through scripts. Ill start with the concept. In 3D (though it will be a 2d appearance to the user), I have 3 cubes and on each face an image. The cubes can be turned 90 degrees in place and I want to know which face and in which orientation each is facing the user. While i believe i can use the rotation values I have decided to do it by giving each cube corner a collider (8 total per cube) and since the cubes will be stationary and just rotating in place I have placed 4 trigger colliders so that 4 corners of each cube facing towards the user will trigger them. So that’s 3 cubes each with a collider on each corner and 4 stationary triggers per cube (Just trying to be as clear as possible not trying to talk down :slight_smile: ). So what I want to do. I want to use the four stationary trigger colliders to get which corner collider is touching them and then using the name of that corner i will be able to pass the 4 names of the corners off the four trigger colliders and then using a game controller script compare them against a list of combinations to determine what side and in what orientation is facing the user. Should be 24 possible orientations. So say side 1 has a 1 facing up on it towards the user. The four corners in the switch colliders will be unique to that orientation. If you turn the cube 90 degrees a different side will face you and only two of the corners that were in triggers will still be in triggers but will be in different triggers and two corners previously not in triggers will be in triggers. I have the cubes and colliders built so i dont need to instantiate them in they will always be there. Each trigger should be able to return a public string with the collider name belonging to the cube’s corner.
This works to get which corner each trigger is in contact with:
public string trigger1;

 public void OnTriggerStay(Collider other) {

	string trigger1 = other.GetComponent<Collider>().name;

my problem comes in getting this string to another “game controller” script to compare with a short list. I can put a different variable in each script for each trigger (for simplicity but more time consuming) or use an array. As a user spins a cube i need it to update the corners and the game controller script. Any help is greatly appreciated. Post any questions for clarification below and i will follow up. thanks!

Your ultimate question is super common, but your situation is quite interesting. I’m a little jealous of the puzzle. I’d feel bad for disallowing it, just know that most questions you’ll have this early can be researched.

First off, there’s a much easier way to determine orientation. By comparing the forward, right, and up directions of the cube to the forward, right, and up directions of world space, you could learn all of this sought orientation data. It’s not that your idea is invalid, but it is much more complicated than it needs to be.

Also, the direction comparison approach would not involve communication among several discrete scripts, or any problems that might arise from the strings being sent in an unexpected order. It only requires a comparison among possible combinations of orientations. It could also detect the “nearest match” to a “perfect” orientation and allow the cube to “snap” to that best match orientation if granular movement is allowed. All around, it’s a superior option.

On to your question, which might serve as an opportunity to learn something worth knowing: Each of the four triggers needs to know the game controller instance. In their script, they need a variable whose type is the type of the game controller.

public GameController gameControllerInstance;

void OnTriggerEnter(Collider other) {
  gameControllerInstance.TakeName( other.gameObject.name );
}

The game controller needs a public method which takes a string. It keeps an array of four strings, which hold the names of the four corners. When a fifth call is made to this method, it erases the current four corners and waits for a 6th, 7th, 8th string, populating the array as it goes. Every multiple-of-four times the method is called, it has an array full of unique corner names you can use to determine orientation.