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

    gsydaydreamer

    Joined:
    Jun 4, 2021
    Posts:
    3
    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");
    4.        
    5.        
    6.         if(cylinder != null)
    7.         {
    8.             var cylinderRenderer = cylinder.GetComponent<Renderer>();
    9.  
    10.  
    11.             cylinderRenderer.material.SetColor("_Color", Color.red);
    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):
    upload_2021-7-21_1-35-15.png

    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?