So as the title says, I´m learning about beginner scripting on Unity(trying to follow scripting tutorials and documentation) and I reached a point where there is a class like this(that one is literally the one from the Unity explanation):
using UnityEngine;
using System.Collections;
public class ExampleBehaviourScript : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
GetComponent<Renderer> ().material.color = Color.red;
}
if (Input.GetKeyDown(KeyCode.G))
{
GetComponent<Renderer>().material.color = Color.green;
}
if (Input.GetKeyDown(KeyCode.B))
{
GetComponent<Renderer>().material.color = Color.blue;
}
}
}
so I tried to apply that on a Unity Scene cube, writing it like this (I only tried to add yellow):
public class Colors : MonoBehaviour
{
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
gameObject.GetComponent<Renderer>().material.color = Color.red;
}
if (Input.GetKeyDown(KeyCode.G))
{
gameObject.GetComponent<Renderer>().material.color = Color.green;
}
if (Input.GetKeyDown(KeyCode.B))
{
gameObject.GetComponent<Renderer>().material.color = Color.blue;
}
if (Input.GetKeyDown(KeyCode.Y))
{
gameObject.GetComponent<Renderer>().material.color = Color.yellow;
}
}
}
And it worked out surprisingly well… Until now. I just tried to access the script now for using it on another object and scene (different from the ones I used it on the 1st time) and now it gave me that error for the 4 colors:
Colors.cs(18,72): error CS0117: 'Color' does not contain a definition for 'red'
So i researched a bit out there in Unity Answers, and i found out I cannot name my class the same as the Unity class, which is Color. Okay, I found that logic although it didn´t cause any problems, so then I tried it modifying the class name to ColorScript, which, if I´m right, shouldn´t cause the conflict, but… :
ColorScript.cs(18,72): error CS0117: 'Color' does not contain a definition for 'red'
and right now I´m kinda lost on this. In the case anyone could help, thanks in advance!! If needed I can send screenshots or the script.