- Home /
Question by
DaniyalAli · Jul 12, 2016 at 08:25 AM ·
randomdirectionrespawn
Object falling from random direction towards the player??
I am trying to make a game and need help. In my game i want to fall number of asteroid towards the player from space...?? here is my script...
using UnityEngine; using System.Collections;
public class Done_GameController : MonoBehaviour { public GameObject hazard; //public Vector3 spawnValues; public Vector3 spawnPosition; public int hazardCount; public float spawnWait; public float startWait; public float waveWait;
void Start ()
{
StartCoroutine (SpawnWaves ());
}
IEnumerator SpawnWaves ()
{
yield return new WaitForSeconds (startWait);
while (true)
{
for (int i = 0; i < hazardCount; i++)
{
Vector3 spawnPosition = Random.onUnitSphere;
spawnPosition.y = Mathf.Clamp (spawnPosition.y, 0.5f, 1f);
float distance = 5 * Random.value + 8.5f;
transform.localPosition = spawnPosition * distance;
Quaternion spawnRotation = Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
yield return new WaitForSeconds (spawnWait);
}
yield return new WaitForSeconds (waveWait);
} } }
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612084614im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Need help with enemy respawn script 1 Answer
Need player to walk in random direction 2 Answers
Random /Organic/ Weapon Inaccuracy 1 Answer
Generate a random direction within min and max angles 2 Answers
Random value from -1 to 1 2 Answers