2014-05-20 3 views
0

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 LVBen 너무 감사합니다 @

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; 



    } 

답변

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


    } 
+1

는 .. 나를 위해 일했다. –