如何关闭网格渲染器

时间:2014-05-20 05:48:58

标签: c# unity3d

我想在x == 3和y == 3时关闭球体的网格渲染器,但该球体在另一个文件(gem.cs)中定义。我希望网格渲染器在另一个名为board.cs的.cs文件中关闭。我只是想让这个宝石(立方体)里面的球体看不见。我该怎么办?

board.cs

public List<Gem> gems = new List<Gem>();
    public int GridWidth;
    public int GridHeight;
    public GameObject gemprefab;


    // Use this for initialization
    void Start () {

       for (int  y = 0; y<GridHeight; y++) { 
                 for (int x= 0; x<GridHeight; x++) {


          GameObject g =  Instantiate(gemprefab, new Vector3 (x, y, 0), Quaternion.identity) as GameObject;
                    g.transform.parent = gameObject.transform;
                    gems.Add(g.GetComponent<Gem>());


          if(y==3 && x==3)
          { //   eslot=new Vector3 (3, 3, 0) as GameObject;

              gemprefab.renderer.enabled = false;


          }

          }
          }
       gameObject.transform.position = new Vector3 (-1.453695f, -1.409445f, 0);


    }

Gem.cs

public GameObject sphere;
    string[] gemMats ={"Red","Blue","Green","Orange","Yellow","Black","Purple"};
    string color="";
    public bool isSelected=false;
    public List<Gem>Neighbors = new List<Gem>();

    // Use this for initialization
    void Start () {

       CreateGem ();
    }
    public void CreateGem()
    {
       color = gemMats[Random.Range(0,gemMats.Length)];
       Material m =Resources.Load("Materials/"+color) as Material; 
       sphere.renderer.material =m;



    }

1 个答案:

答案 0 :(得分:0)

public List<Gem> gems = new List<Gem>();
    public int GridWidth;
    public int GridHeight;
    public GameObject gemprefab;


    // Use this for initialization
    void Start () {

       for (int  y = 0; y<GridHeight; y++) { 
                 for (int x= 0; x<GridHeight; x++) {


          GameObject g =  Instantiate(gemprefab, new Vector3 (x, y, 0), Quaternion.identity) as GameObject;
                    g.transform.parent = gameObject.transform;
                    gemComponent = g.GetComponent<Gem>();
                    gems.Add(gemComponent);


          if(y==3 && x==3)
          { //   eslot=new Vector3 (3, 3, 0) as GameObject;

              //gemprefab.renderer.enabled = false;
              gemComponent.sphere.renderer.enabled = false;

          }

          }
          }
       gameObject.transform.position = new Vector3 (-1.453695f, -1.409445f, 0);


    }