2016-08-04 21 views
1

我有一個向前跳動的立方體,每次向前移動時都會添加更多的地面。我想要的是讓球員每次向前跳進球員過去並且不再能看到的地面被摧毀。但我不知道如何做到這一點。這是我到目前爲止的代碼:如何刪除播放器後面的地面和視野之外的地面?

using UnityEngine; 
using System.Collections; 

public class Generation : MonoBehaviour { 

public GameObject Water; 
public GameObject Road; 
public GameObject Grass; 

int firstRand; 
int secondRand; 
int disPlayer = 1; 

Vector3 intPos = new Vector3(0, 0, 0); 


// Update is called once per frame 
void Update() { 
    if (Input.GetButtonDown ("up")) { 

     firstRand = Random.Range (1, 4); 
     if (firstRand == 1) { 
      secondRand = Random.Range (1, 5); 
      for (int i = 0; i < secondRand; i++) { 
       intPos = new Vector3 (0, 0, disPlayer + 3); 
       disPlayer+=3; 
       GameObject GrassIns = Instantiate (Grass) as GameObject; 
       GrassIns.transform.position = intPos; 


      } 
     } 
     if (firstRand == 2) { 
      secondRand = Random.Range (1, 5); 
      for (int i = 0; i < secondRand; i++) { 
       intPos = new Vector3 (0, 0, disPlayer + 3); 
       disPlayer+=3; 
       GameObject RoadIns = Instantiate (Road) as GameObject; 
       RoadIns.transform.position = intPos; 
      } 


     } 
     if (firstRand == 3) { 
      secondRand = Random.Range (1, 5); 
      for (int i = 0; i < secondRand; i++) { 
       intPos = new Vector3 (0, 0, disPlayer + 3); 
       disPlayer+=3; 
       GameObject WaterIns = Instantiate (Water) as GameObject; 
       WaterIns.transform.position = intPos; 

      } 



     } 
    } 
} 

} 
+0

你留下太多東西了。這是2D還是3D遊戲?也許應該上傳一張地面和球員的照片.... – Programmer

回答

2

最簡單的解決辦法是增加一個遊戲對象與對撞機爲您的播放器的一個孩子。將它放在足夠遠的地方,以便當平臺進入對撞機時,將其摧毀並且不顯示。

相關問題