Problems with script var sharing

I’m making a game where the player can change color to be able to walk on or go though colored blocks. Below are the two script I have created to do the task. The PlayerColorChecker.cs go on the block and the PlayersCurrentColor.cs goes on the player script. In the code there are debuging line where im checking to see if var that im am trying to share is show, but in the space where the value should be it is blank why is this, also the script is on the RigidBodyFPSController from the sample assets if this changes anything. Thank you.

Your first script is referencing the Player GameObject, but you need to reference the component on the GameObject.

Add the following to you variable declarations:

public PlayersCurrentColor playerColor;


Then when you want to reference the colour, use the following:

Debug.Log("color: " + playerColor.PlayerColor);

If you want to reference it directly, you can instead do the following:

Debug.Log("color: " + Player.GetComponent<PlayersCurrentColor>().PlayerColor);

Although it’s better practise to grab it in a variable first.