投掷后产生 [英] Spawn after throw
本文介绍了投掷后产生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个足球比赛项目.我想要一个球体,在抛出第一个球体后,我必须生成另一个球体.这是我尝试过的:
I am working on a football game project. I want a sphere I have to spawn another sphere after I throw the 1st sphere. Here's something I tried:
public class spawn : MonoBehaviour {
public Transform[] SpawnPoints;
public float SpawnTime;
public GameObject ball;
// Use this for initialization
void Start () {
InvokeRepeating ("SpawnBalls", SpawnTime, SpawnTime);
}
void SpawnBalls(){
if (transform.position.z > -0.904 ) {
int SpawnIndex = Random.Range (0, SpawnPoints.Length);
Instantiate (ball, SpawnPoints [SpawnIndex].position, SpawnPoints [SpawnIndex].rotation);
}
}
}
推荐答案
如果最后掷出的球足够远,则只需实例化一个新球.试试这个:
Simply instantiate a new ball if the last ball thrown is far enough. Try this:
public class spawn : MonoBehaviour {
public Transform[] SpawnPoints;
public GameObject ball;
public GameObject lastBall;
// Use this for initialization
void Start () {
int SpawnIndex = Random.Range (0, SpawnPoints.Length);
lastBall = Instantiate (ball, SpawnPoints [SpawnIndex].position, SpawnPoints [SpawnIndex].rotation) as GameObject;
}
void Update(){
if (lastBall.position.z > -0.904 ) {
int SpawnIndex = Random.Range (0, SpawnPoints.Length);
lastBall = Instantiate (ball, SpawnPoints [SpawnIndex].position, SpawnPoints [SpawnIndex].rotation) as GameObject;
}
}
}
这篇关于投掷后产生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文