- Home /
Question by
soyeon9897 · Sep 24, 2018 at 08:15 AM ·
c#changecolourchange color
Changing a material colour of an object c#
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class WhiteSheep : MonoBehaviour {
public Color altColor = Color.white;
//I want to change the colour from white to red
public Renderer rend;
void Start ()
{
rend = GetComponent<Renderer>();
//so we can access the colour
rend.material.color = altColor;
//this is to set the initial color 0f
altColor.b += 0.1f;
//it alters the color
rend.material.color = altColor;
//this is to assign the changed color
}
}
I want to make a sheep change its colour, but when I play it, I can see the colour change on the ride hand side in unity, but the colour of the sheep doesn't change. Can you please help me?
Comment
Answer by OfficeThrashing · Sep 24, 2018 at 08:57 AM
Try This
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WhiteSheep : MonoBehaviour
{
public Color altColor = Color.white;
//I want to change the colour from white to red
public Renderer rend;
void Start()
{
rend = GetComponent<Renderer>();
//so we can access the colour
rend.material.color = altColor;
//this is to set the initial color 0f
altColor = Color.red;
//it alters the color
rend.material.color = altColor;
//this is to assign the changed color
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to adjust the speed of an object? 1 Answer