【发布时间】:2015-02-02 08:01:01
【问题描述】:
我有一个游戏对象,它向前移动并每隔一秒左右生成一个预制件。唯一的问题是产卵似乎不均匀,有时物体相距很远,有时它们重叠。我可以通过改变生成时间和距离来解决这个问题,但是当我在 ios 上测试它时它又坏了。
我尝试创建一个脚本,该脚本将游戏对象推出另一个对象,但它推出了,然后对象击中另一个对象,然后以另一种方式。
我想要做的是让生成器向前移动并向下放置一个预制件,这样预制件就不会重叠。我需要这个在 ios 上工作。我认为它可能是由于
这里是生成脚本:
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public GameObject[] obj;
//public float spawnMin = 1;
//public float spawnMax = 1;
//public float spawnDistance = 0.1f;
//private float barDisplay = 3;
public float timeLeft = 0.1f;
static bool finishTimer = false; //i made this global so you can access from other scripts
static bool timerStarted = false;
//private GameObject GroundSpawner;
// Use this for initialization
void Start () {
timerStarted = true;
}
void Update(){
Timer ();
transform.Translate(Vector3.forward * 0.1f);
}
void Timer(){
if (timerStarted == true) {
timeLeft -= Time.deltaTime;
if (timeLeft <= 0.0f) {
Spawn ();
timerStarted = false;
}
}
}
void Spawn(){
//GroundSpawner = GameObject.Find ("Ground Spawner");
//if (GroundSpawner.transform.position) {
//Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
Invoke ("Spawn", 1.75f);
Instantiate (obj [Random.Range (0, obj.Length)], transform.position, Quaternion.identity);
// }
}
}
这是另一个游戏对象脚本推出的基础:
using UnityEngine;
using System.Collections;
public class GroundHittingSelf : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision other) {
Debug.Log("Hitting Ground without tag");
if (other.gameObject.tag == "Ground") {
//transform.position += new Vector3(0, 0, 0.1f);
Debug.Log("Hitting Ground with tag");
}
}
}
【问题讨论】:
-
好吧,无法准确理解您要做什么。您可以发布任何带有您的问题的图片(屏幕截图)吗?