- Home /
Player changes color on button collision in VR?,Changing player color on button collision VR?
To keep things short, I am new to coding and Unity in general.
I tried to find good tutorials, but none of them helped me out. I am currently making a "Gorilla Tag" fangame and need some assistance on changing the player's color. I want there to be a button system, where whatever button you press, that is the color you have. Here is the code I have that doesn't seem to want to work.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ColorChange : MonoBehaviour
 {
     public Material m_Material;
     
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         void onCollisionEnter()
         {
             m_Material.color = Color.blue;
         }
 
     }
 }
Here is also an image that could possibly help. 
,Haven't seen this on a tutorial anywhere, so I'm asking here.
I am making a "Gorilla Tag" fangame in VR. I have used Unity before, but this is my first time coming back to it in a long time. I don't know how to code well, so that may be part of the problem for I usually use Unreal Engine. How would I make it to where I can press a trigger button and be able to change my player's material color? Here's what I am going with so far but it doesn't seem to work.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ColorChange : MonoBehaviour
 {
     public Material m_Material;
     
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         void onCollisionEnter()
         {
             m_Material.color = Color.blue;
         }
 
     }
 }

Answer by rh_galaxy · May 07 at 05:50 AM
You need to set the material to the MeshRenderer.
 public GameObject obj; //set in inspector, must have MeshRenderer
 MeshRenderer objMesh;
 void Start()
 {
     objMesh = obj.GetComponent<MeshRenderer>();
 }
 void Update()
 {
     void onCollisionEnter()
     {
         m_Material.color = Color.blue;
         obj.material = m_Material;
     }
 }
Answer by PalominoKid · May 07 at 05:36 PM

 These are the four errors I am getting from this, I don't understand how to fix it. Could you explain how to fix it? @rh_galaxy
 These are the four errors I am getting from this, I don't understand how to fix it. Could you explain how to fix it? @rh_galaxy
Your answer
 
 
             Follow this Question
Related Questions
OVR Grabbable causes object to ignore OnCollisionEnter/Exit 2 Answers
Gradually Change Color from Original to Red with Each Collision 1 Answer
Anyway to change the colour of collider outline in the editor? 1 Answer
Sword slashing logic on Gear VR using controller? 0 Answers
Destroy object after time Only if raycast is colliding; 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                