小球快跑
代码展示
1.损坏障碍
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AutoDestoryBarrier : MonoBehaviour {
private void OnTriggerEnter(Collider other)
{
Destroy(other.gameObject);
}
}
2.控制障碍
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BarrierControl : MonoBehaviour {
public GameObject player;
public GameObject BarrierPre;
public GameObject CurrentBarrier;
public int BarrierInterval = 10;
void Start () {
}
void Update () {
AutCreatBarrier();
}
public void AutCreatBarrier()
{
if(player.transform.position.x>CurrentBarrier.transform.position.x)
{
//生成新的障碍物
float targetX = CurrentBarrier.transform.position.x+BarrierInterval;
float targetY = RandomBarrierPositionY();
Vector3 t