Hi, Any solutions would be appreciated. I’m creating a 3D Match game and unable to assign colors due to Error:
Error CS0119: Expression denotes a ‘type’, where a ‘variable’, ‘value’ or ‘method group’ was expected
C#**
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Gem : MonoBehaviour
{
public GameObject sphere;
string[ ] gemMats = {“Red”,“Blue”,“Green”,“Orange”,“Yellow”,“Black”,“Purple”};
string color=“”;
public List Neighbors = new List();
// Use this for initialization
void Start ()
{
CreateGem();
}
// Update is called once per frame
void Update ()
{
}
public void CreateGem()
{
color = gemMats[Random.Range(0,gemMats.Length)];
Material m =Resources.Load(“Material/”+color) as Material;
sphere.GetComponent(Material);
//sphere.renderer.material =m;
}
public void AddNeighbor(Gem g)
{
if(Neighbors.Contains(g))
Neighbors.Add(g);
}
public void RemoveNeighbor(Gem g)
{
Neighbors.Remove(g);
}
void OnMouseDown()
{
}
}
Thanks, Melvin
Please use code tags for code Using code tags properly - Unity Engine - Unity Discussions and also paste the complete error message including the line number of the error.
Opps My Mistake I’m really new to Unity
Error: Line(25,47): error CS0119: Expression denotes a ‘type’, where a ‘variable’, ‘value’ or ‘method group’ was expected
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Gem : MonoBehaviour
{
public GameObject sphere;
string[ ] gemMats = {“Red”,“Blue”,“Green”,“Orange”,“Yellow”,“Black”,“Purple”};
string color=“”;
public List Neighbors = new List();
// Use this for initialization
void Start ()
{
CreateGem();
}
// Update is called once per frame
void Update ()
{
}
public void CreateGem()
{
color = gemMats[Random.Range(0,gemMats.Length)];
Material m =Resources.Load(“Material/”+color) as Material;
sphere.GetComponent(Material);
//sphere.renderer.material =m;
}
public void AddNeighbor(Gem g)
{
if(Neighbors.Contains(g))
Neighbors.Add(g);
}
public void RemoveNeighbor(Gem g)
{
Neighbors.Remove(g);
}
void OnMouseDown()
{
}
}
Ok, not quite, the code should be inside the block 
Anyway, I’m guessing this is your problem sphere.GetComponent(Material); there is no version of GetComponent<> that takes an argument, so it should just be sphere.GetComponent();
You also want to assign it to something if you want to use it Renderer renderer = sphere.GetComponent<Renderer>();
Then you can use renderer.material = m