Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question MRTK changing Button Color on Button Pressed

Discussion in 'VR' started by gsydaydreamer, Jul 21, 2021.

  1. gsydaydreamer


    Jun 4, 2021
    Hello there. I'm just trying to achieve that a button is disabled for a second after it is pressed or at least color it red for that time.

    I tried to achieve it with this script:

    Code (CSharp):
    1.     public void OnButtonPressed()
    2.     {
    3.         GameObject cylinder = GameObject.FindWithTag("Button");
    6.         if(cylinder != null)
    7.         {
    8.             var cylinderRenderer = cylinder.GetComponent<Renderer>();
    11.             cylinderRenderer.material.SetColor("_Color",;
    12.         }
    13.     }
    It's the PressableRoundButton Prefab of the MRTK. On this button, there are already existing events and I thought that I can call my script method after the event is triggered and change the color but it does not work (the method is called):

    The material for the inner part of the button is in a cylinder:
    upload_2021-7-21_1-34-8.png upload_2021-7-21_1-34-24.png

    What am I doing wrong?