top of page
Search

Debug Challenge: Color Changing

  • Writer: Keshav Batra
    Keshav Batra
  • Oct 1, 2021
  • 1 min read

My task this time was to try and debug the code and to get the pillars to change colors. I found out that my on trigger enter had the wrong get component and it had to be set to Player_S. I also had to make the pillar a public game object.


Color initialColor; //The color it starts with
public Color colorToChange; //The color it changes to
public GameObject pillar;



private void Start()
    {
        initialColor = GetComponent<Renderer>().material.color; //Sets the value to the inital value variable and gets the color of the renderer
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.GetComponent<Player_S>()) //If the player steps on the trigger
        {
            pillar.GetComponent<Renderer>().material.color = colorToChange; //Changes the color of the pillar whenever the player steps on the platform
        }
    }

    private void OnTriggerExit(Collider other)
    {
        pillar.GetComponent<Renderer>().material.color = initialColor; //Color of the pillar changes back to the original color
    }



 
 
 

Comments


bottom of page