Question by
Muhammad_Sannan · Dec 18, 2020 at 11:02 AM ·
material color
Color Doesn't Change When giving it random value?
public class SpawnManager : MonoBehaviour
{
[SerializeField] private GameObject[] Platforms, SafePlatforms, DangerPlatforms;
[SerializeField] private GameObject MainTower;
private MeshRenderer SP_Meshrederer, DP_Meshrederer;
void Start()
{
//For Spawning
/*for (int YPos = 84; YPos > -84; YPos = YPos - 4)
{
if (YPos % 4 == 0)
{
int RandomInstantiation = Random.Range(0, 4);
Vector3 SpawnPosition = new Vector3(0, YPos, 0), Scale = new Vector3(1, 0.1428571f, 1);
GameObject platform = Instantiate(Platforms[RandomInstantiation],
SpawnPosition, Quaternion.identity);
platform.transform.parent = MainTower.transform;
platform.transform.localScale = Scale;
}
}*/
SafePlatforms = GameObject.FindGameObjectsWithTag("SafePlatform");
DangerPlatforms = GameObject.FindGameObjectsWithTag("DangerPlatform");
Color SP_Color = new Color(Random.Range(0, 256), Random.Range(0, 256), Random.Range(0, 256)),
DP_Color = new Color(Random.Range(0, 256), Random.Range(0, 256), Random.Range(0, 256));
foreach (GameObject platform in SafePlatforms)
{
platform.GetComponent<Renderer>().material.color = SP_Color;
}
foreach (GameObject platform in DangerPlatforms)
{
platform.GetComponent<Renderer>().material.color = DP_Color;
//DP_Meshrederer.material.color = DP_Color;
}
}
}
Hi guys i am a beginner and i was stuck here that when i give my material.color a random value through script, the color does not change but when I go to unity inspector open the materials color tab the cursor is on the random color but the material is white and when i write material.color = Color.Red than it works and the object color is changed to red ?? Any help is appriciated!
[1]: /storage/temp/172749-screenshot-2020-12-18-111854.png
screenshot-2020-12-18-111854.png
(176.3 kB)
Comment