- Home /
Passing More Then One Int Into Another Script As A GUI
I have a simple CubeManager script the allows me to set a certain cube into a CubeType, each with it's very own unique number from 0 - 9. What I'm trying to figure out and do is that when a cube is selected it would pass it's number value into another script to display as a GUI. How should I go about doing this? If I am correct the default cNumber way I set it up would cause confusing when passing numbers. (I have 10 cubes in my scene using the same script).
using UnityEngine;
using System.Collections;
public class CubeManager : MonoBehaviour {
public enum CubeType {cubeZero, cubeOne, cubeTwo, cubeThree, cubeFour, cubeFive, cubeSix,cubeSeven, cubeEight, cubeNine}
public CubeType cubeNumType;
public bool cubeClick = false;
public int cNumber;
public static int guiNum;
public Material matCubeZero;
public Material matCubeOne;
public Material matCubeTwo;
public Material matCubeThree;
public Material matCubeFour;
public Material matCubeFive;
public Material matCubeSix;
public Material matCubeSeven;
public Material matCubeEight;
public Material matCubeNine;
void Start ()
{
CubeNum();
}
void Update ()
{
if(cubeClick)
{
renderer.material.color = Color.green;
print (cNumber);
}
else
{
renderer.material.color = Color.white;
}
}
public void CubeNum()
{
switch (cubeNumType)
{
case CubeType.cubeZero:
renderer.material = matCubeZero;
cNumber = 0;
guiNum = cNumber;
PlayerPrefs.GetInt("Number0", guiNum);
break;
case CubeType.cubeOne:
renderer.material = matCubeOne;
guiNum = cNumber;
PlayerPrefs.GetInt("Number1", guiNum);
cNumber = 1;
break;
case CubeType.cubeTwo:
renderer.material = matCubeTwo;
cNumber = 2;
break;
case CubeType.cubeThree:
renderer.material = matCubeThree;
cNumber = 3;
break;
case CubeType.cubeFour:
renderer.material = matCubeFour;
cNumber = 4;
break;
case CubeType.cubeFive:
renderer.material = matCubeFive;
cNumber = 5;
break;
case CubeType.cubeSix:
renderer.material = matCubeSix;
cNumber = 6;
break;
case CubeType.cubeSeven:
renderer.material = matCubeSeven;
cNumber = 7;
break;
case CubeType.cubeEight:
renderer.material = matCubeEight;
cNumber = 8;
break;
case CubeType.cubeNine:
renderer.material = matCubeNine;
cNumber = 9;
break;
}
}
}
you really need to learn how to use List or at least an array.
there is an incredible, astounding amount of lessons, material, documentation, tutorials and so on regarding how to access scripts on other objects, components. There must be 100s of pages on the internet regarding the issue, and 1,000s of questions here.
read all of this:
http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Components.html
Your answer
Follow this Question
Related Questions
Values not moving to Game Over screen or the Game over doesn't somehow work. 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
NullreferenceException, BeginScrollView style change 3 Answers
Scaled GUI 1 Answer