2016-06-02 3 views
1
GameObject Lightwall; // It's here we store the name tag 
GameObject LightWalls; //the name of the tag 
Object[] LightWall; 

public GameObject wallPrefab; 
Collider2D wall; // this is the wall which is surrounding the player 
Collider2D walls; //had to make a new because of this error `wall' conflicts with a declaration in a child block 

Vector2 lastWallEnd; 

void OnTriggerEnter2D(Collider2D co) 
{ 
    if (co != wall && co.tag != "Power Up") 
    { 
     healthP1--; 

     if (healthP1 == 1) 
     { 
      transform.position = Vector3.zero; 

      var Lightwall = GameObject.FindWithTag("LightWalls"); 
      foreach (var walls in LightWall) //NullReferenceException: Object reference not set to an instance of an object this is the error that i'm getting: Playermovmnet.OnTriggerEnter2D(UnityEngine.Collider2D co) 
      { 
       Destroy(Lightwall); 
      } 

     } 

내 문제는 코드 foreach (var walls in LightWall)입니다. 다른 벽을 사용하려고했지만이 오류가 나타났습니다 : wall conflicts with a declaration in a child block. 그것을 제거하는 유일한 방법은 비슷한 다른 것을 만드는 것이 었습니다. `파괴 (벽)에`; 잘못된 매개 변수를 사용하여 파괴하려고하는foreach로 arraylist를 파괴하는 방법

+0

변경'파괴 (얇은 두께)의 사용 발렌틴처럼 – Valentin

+0

위했다 '는 올바른 방법입니다 하지만 당신의 코드 주석 - NullReferenceException에서 말했듯이 문제는 이전 라인에서 null 참조를 반환합니다 "var Lightwall = GameObject.FindWithTag ("LightWalls ");" – terrybozzio

답변

0

wall 대신 LightWall

if (LightWall != null) 
{ 
    foreach (var walls in LightWall) 
    { 
     Destroy(walls); 
    } 
} 
+0

문제는'Lightwall = GameObject.FindWithTag ("LightWalls");'Lightwall은 GameObject입니다. – Valentin

+0

그래서 나는 Lightwall = GameObject.FindWithTag ("LightWalls"); –

+0

그걸 없애면 어떻게 파괴 할 벽 목록을 얻을 수 있을까요? –