I have a public Color winColor
var in my gameController.cs
script. I am setting its value in the Start()
. Now I want to get its value in another script check.cs
.
Now I since it is public I have used GameObject.Find("gameController").GetComponent<gamePlay>().winColor;
The issue here is that it is displaying a different value.
This is my code in tile.cs
private Color winingColor;
void Start ()
{
winingColor = GameObject.Find("gameController").GetComponent<gamePlay>().winColor;
Debug.Log(winingColor);
}
void Update ()
{
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
bool overSprite = this.GetComponent<SpriteRenderer>().bounds.Contains(mousePosition);
if (overSprite)
{
if (Input.GetButton("Fire1"))
{
if (this.GetComponent<SpriteRenderer>().color == winingColor)
{
float x = this.gameObject.transform.position.x;
this.gameObject.transform.position = new Vector3(x, 3.5f, 0.0f);
}
}
}
}
gameController.cs
Code
public GameObject ball;
public List<GameObject> tiles;
private Color [] colors = { new Color(0,1,0,1), new Color(1,0,0,1), new Color(1,1,1,1), new Color(0,0,1,1), new Color(1,1,0,1), new Color(0, 0, 0, 1)};
public Color winColor;
// Use this for initialization
void Start ()
{
winColor = colors[1];
Debug.Log("con wincolor:" + winColor);
ball.GetComponent<SpriteRenderer>().color = colors[1];
tiles[0].GetComponent<SpriteRenderer>().color = colors[0];
tiles[1].GetComponent<SpriteRenderer>().color = colors[1];
tiles[2].GetComponent<SpriteRenderer>().color = colors[3];
tiles[3].GetComponent<SpriteRenderer>().color = colors[4];
}
The value of winColor
in gameController.cs
is RGBA(1.000, 0.000, 0.000, 1.000)
But in tile.cs
I am getting RGBA(0.000, 0.000, 0.000, 0.000)
Any thoughts?