Search Unity

[Hololens] Changing color not working

Discussion in 'VR' started by Zatchy96, Apr 20, 2018.

  1. Zatchy96

    Zatchy96

    Joined:
    Mar 15, 2018
    Posts:
    1
    I'm trying to change the color of the cube once it's pressed, I'm trying to change the color of the cube once it's pressed, but when I click it does not change color.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3. using HoloToolkit.Unity.InputModule;
    4.  
    5. public class ClickExample : MonoBehaviour, IInputClickHandler
    6. {
    7.  
    8.     private Color[] colors = new Color[] { Color.red, Color.cyan };
    9.     private int i = 0;
    10.     private Renderer rend;
    11.    // public GameObject cube2;
    12.     void Start()
    13.     {
    14.      
    15.         rend = GetComponent<Renderer>();
    16.  
    17.     }
    18.  
    19.     public void OnInputClicked(InputClickedEventData eventData)
    20.     {
    21.      
    22.        rend.material.color = colors[i];
    23.         i = (i + 1) % colors.Length;
    24.     }
    25.  
    26.  
    27. }

    Can you help me? Thanks so much
     
  2. jghospital

    jghospital

    Joined:
    Nov 22, 2017
    Posts:
    17
    It seems to be ok, try adding some debug messages to the input event method, so that you can be sure it's being called. Also change the get component call to that method, sometimes it fails or get lost when it's call abroad asignation, we don't know why.