Reputation: 907
I'm trying to change the colour of some materials in unity with the following code:
public List<GameObject> targets = new List<GameObject>();
public string name;
public Color setToColor = Color.white;
public Color ChangeObjectMaterialColour()
{
foreach(GameObject t in targets)
if(t.renderer != null)
{
if(t.renderer.materials != null)
{
foreach(Material m in t.renderer.materials)
if(m.name.Equals(name))
m.color = setToColor;
}
}
return Color;
}
The should take in a list of object I want to change the colour of (which I'll store in the list) and change it to the colour I specifiy. This code is stored in a serpeate class.
Then in my other class where I'm calling this method I'm doing as follows:
private ChangeObjectColour colour;
if(hit.collider.gameObject.tag == "Colour1")
{
hit.collider.gameObject.renderer.material.color = colour.ChangeObjectMaterialColour();
}
However this has resulted in the following error:
Expression denotes a
type', where a
variable',value' or
method group' was expected
When I click on it, Unity takes me to return Color;
at the end of my first method.
How can I defeat this bug?
Upvotes: 1
Views: 1890
Reputation: 1062502
Indeed:
return Color;
what Color
did you intend to return? Should this be return setToColor;
? or maybe the entire method should be void
and not return
anything...
Upvotes: 1