我希望能够在游戏中随机生成不同大小的平台' ,但我不知道该怎么做。
请你帮我解决这个问题,因为它在游戏中发挥了重要作用。
这是我到目前为止编写的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Platform_Generator : MonoBehaviour {
public GameObject[] thePlatforms;
public Transform generationPoint;
private float distanceBetween;
private float platformWidth;
public float distanceBetweenMin;
public float distanceBetweenMax;
private float platformHeight;
private float platformHeightMin;
private float platformHeightMax;
// Use this for initialization
void Start ()
{
platformWidth = 7;
platformHeightMax = 0.3f;
platformHeightMin = -3.9f;
}
// Update is called once per frame
void Update ()
{
if (transform.position.x < generationPoint.position.x)
{
platformHeight=Random.Range(platformHeightMax,platformHeightMin);
distanceBetween = Random.Range(distanceBetweenMin, distanceBetweenMax);
transform.position = new Vector3 (transform.position.x + platformWidth + distanceBetween, platformHeight, transform.position.z);
Instantiate (thePlatforms[UnityEngine.Random.Range] , transform.position, transform.rotation);
}
}
}