- Home /
Problem with changing the colour of a 3D model on keypress
I'm creating an interactive map and need to change the colours of some of the 3d models on the map. However, the script i am using doesnt change the colour of the model in the game mode but the colour does change in the inspector. I have tried changing the material on the initial model and also tried the unlit setting which was mentioned in another answer. I have a directional light in the scene which is pointing directly towards the model and yet I still cannot get it to work. Could someone please help me?
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColorChange : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.S)) {
this.GetComponent<Renderer> ().material.SetColor ("_TintColor", Color.red);
}
}
}
Answer by dishant27 · Feb 24, 2018 at 04:25 PM
Just change the color of the material "........material.color = Color.red;"
Your answer
Follow this Question
Related Questions
No color picker 0 Answers
Why can't I change options in Lighting? 0 Answers
Image Filling To Obtain Color Scale 0 Answers
How to change a buttons color? 2 Answers
How do I make a color lerp reset back to the original color after I click on a new tile? 0 Answers