パス上にランダムに旅行のプレーヤーを保つために、私は下のリンクでゲームを再作成しようとしています: https://www.youtube.com/watch?v=88kMVPzybSwユニティどのよう
これまでのところ、私はノーとランダムなパスを生成することに成功したジャンプを入れて(まだジャンプすることはできません問題)。私はこの乱雑さのための情報を保存していないので、私はどのように私のプレーヤーをパスに従うことができますか?
EDIT:これは私のtilemanagerクラスです。このImを使ってランダムパスを生成します。私の質問は、私は上記のゲームのように自分のプレーヤーがこの道に沿って動くように強制することができますか?
パブリッククラスTileManager:MonoBehaviour {
public GameObject[] tilePrefabs;
public GameObject currentTile;
private Stack<GameObject> leftTiles = new Stack<GameObject>();
private Stack<GameObject> topTiles = new Stack<GameObject>();
private static TileManager instance;
public static TileManager Instance
{
get
{
if (instance == null) {
instance = GameObject.FindObjectOfType<TileManager>();
}
return instance;
}
}
public Stack<GameObject> LeftTiles
{
get { return leftTiles; }
set { leftTiles = value; }
}
public Stack<GameObject> TopTiles
{
get{ return topTiles; }
set{ topTiles = value; }
}
// Use this for initialization
void Start() {
CreateTiles(50);
for (int i = 0; i < 20; i++) {
SpawnTile();
}
}
// Update is called once per frame
void Update() {
}
public void CreateTiles(int amount)
{
for (int i = 0; i < amount; i++) {
LeftTiles.Push(Instantiate(tilePrefabs[0]));
TopTiles.Push(Instantiate(tilePrefabs[1]));
LeftTiles.Peek().name = "LeftTile";
LeftTiles.Peek().SetActive(false);
TopTiles.Peek().name = "TopTile";
TopTiles.Peek().SetActive(false);
}
}
public void SpawnTile() {
//before we spawn we need to check if theres enough tiles, if not create more.
if (LeftTiles.Count == 0 || TopTiles.Count == 0) {
CreateTiles(10);
}
int randomIndex = Random.Range(0,2);
if (randomIndex == 0) {
GameObject temp = LeftTiles.Pop();
temp.SetActive(true);
temp.transform.position = currentTile.transform.GetChild(0).transform.GetChild(randomIndex).position;
currentTile = temp;
}
else if(randomIndex == 1)
{
GameObject temp = TopTiles.Pop();
temp.SetActive(true);
temp.transform.position = currentTile.transform.GetChild(0).transform.GetChild(randomIndex).position;
currentTile = temp;
}
int spawnPickUp = Random.Range(0 , 10);
if (spawnPickUp == 0) {
currentTile.transform.GetChild(1).gameObject.SetActive(true);
}
//currentTile = (GameObject) Instantiate(tilePrefabs[randomIndex], currentTile.transform.GetChild(0).transform.GetChild(randomIndex).position, Quaternion.identity);
}
public void ResetGame() {
Application.LoadLevel(Application.loadedLevel);
}
}
あなたがこれまで持っていたコードを投稿してください。ありがとう! –
この質問は非常にあいまいで、特定の形ではありません –
パスの作成方法によって異なります。 –