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<Gem> Neighbors = new List<Gem>(); // 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<Renderer>(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 http://forum.unity3d.com/threads/using-code-tags-properly.143875/ 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 Code (csharp): 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<Gem> Neighbors = new List<Gem>(); // 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<Renderer>(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<Renderer>(Material); there is no version of GetComponent<> that takes an argument, so it should just be sphere.GetComponent<Renderer>(); You also want to assign it to something if you want to use it Code (csharp): Renderer renderer = sphere.GetComponent<Renderer>(); Then you can use Code (csharp): renderer.material = m