我正在彼此下方实例化一个平台,您可以在下面的图片中看到
但我想生成这样的平台
那么我该怎么做呢?您可以在下面阅读我的代码,该代码仅在 Y 位置生成彼此下方的平台。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class platformGeneration : MonoBehaviour
{
public int numOfPlatforms;
public GameObject platform;
public Transform spawnPosition;
// Start is called before the first frame update
void Start()
{
Vector3 pos = spawnPosition.GetComponent<Transform>().position;
for (int i = 0; i < numOfPlatforms; i++)
{
spawnPlatofrm(pos + new Vector3(i+2,-i - 5, 0));
//spawnPlatofrm(pos + new Vector3(0, -i - 5, -i - 2));
//for (int j = 0; j < numOfPlatforms; j++)
//{
// spawnPlatofrm(pos + new Vector3(0, -j - 5, -j - 2));
//}
//spawnPlatofrm(pos + (Vector3.right * i));
}
}
void spawnPlatofrm(Vector3 spawnPosition)
{
Instantiate(platform, spawnPosition, Quaternion.identity);
}
}