简体   繁体   English

如何关闭网格渲染器

[英]How to turn off the mesh renderer

I want to turn off the mesh renderer of the sphere when x==3 and y==3, but that sphere is defined in another file (gem.cs). 我想在x == 3和y == 3时关闭球体的网格渲染器,但是该球体是在另一个文件(gem.cs)中定义的。 I want the mesh renderer to turn off in a different .cs file named as board.cs. 我希望在另一个名为board.cs的.cs文件中关闭网格渲染器。 I just want to make this gem(cube) have a sphere inside it to be invisible. 我只想使此gem(cube)内部具有一个球形,使其不可见。 How can I do it? 我该怎么做?

board.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;



    }
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);


    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM