So I have 3 sprites.
1 is player, which is a white square.
2 is the ground/level, which is black
3 is a flag to finish the level
The background is default to white.
When you press “S” , you change black, and the floor changes to white.
You can never see the player or the level simultaneously, which is the main mechanic in this game.
This script will change me from black to white, but not to any other object except for the flag (These are all sprites btw)
It for whatever reason will not change color when I want it too. Only the player and the flag.
I have 2 separate scripts. They are both the exact same, except flipped so you are never the same color as the level. 1 is on the player, and 1 should be on the level sprite.
Any thoughts?..
Code attached to player:
using UnityEngine;
using System.Collections;
public class ColorSwitch : MonoBehaviour
{
private bool colorSet = true;
void Start ()
{
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.S))
{
colorSet = !colorSet;
}
if (colorSet == true)
{
gameObject.GetComponent<SpriteRenderer> ().color = Color.white;
Debug.Log ("PLAYER should be white!");
}
else if (colorSet == false)
{
gameObject.GetComponent<SpriteRenderer> ().color = Color.black;
Debug.Log ("PLAYER should be black!");
}
}
}
Code attached to level:
using UnityEngine;
using System.Collections;
public class LevelColorSwitch : MonoBehaviour
{
private bool colorSet = true;
void Start ()
{
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.S))
{
colorSet = !colorSet;
}
if (colorSet == true)
{
gameObject.GetComponentInChildren<SpriteRenderer> ().color = Color.black;
Debug.Log ("PLAYER should be white!");
}
else if (colorSet == false)
{
gameObject.GetComponentInChildren<SpriteRenderer> ().color = Color.white;
Debug.Log ("PLAYER should be black!");
}
}
}