Search Unity

3D Match Color Renderer

Discussion in 'Scripting' started by melvinbutler, Jul 5, 2015.

  1. melvinbutler

    melvinbutler

    Joined:
    Jul 2, 2015
    Posts:
    9
    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
     
  2. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    969
  3. melvinbutler

    melvinbutler

    Joined:
    Jul 2, 2015
    Posts:
    9
    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):
    1.  
    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()
    {
    }
    }
     
  4. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    969
    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):
    1. Renderer renderer = sphere.GetComponent<Renderer>();
    Then you can use
    Code (csharp):
    1. renderer.material = m