Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

I need Help spawning game objects (enemys) from the top of my screen,How can i spawn my Game Objects on top of the sreec randomly

$
0
0
Hello, I'm programming a Spaceshooter game and I'm basically done but the only problem is that my gameobject (Asteroids) are not spawning randomly , they are spawning just in one line and i want them how i already said spawning randomly. This is the code im using thank you for helping<3 (Using C#). using System.Collections; using System.Collections.Generic; using UnityEngine; public class deployAsteroids : MonoBehaviour { public GameObject asteroidPrefab; public float respawnTime = 1.0f; private Vector2 screenBounds; // Use this for initialization void Start() { screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.height, Screen.width, Camera.main.transform.position.z)); StartCoroutine(asteroidWave()); } private void spawnEnemy() { GameObject a = Instantiate(asteroidPrefab) as GameObject; a.transform.position = new Vector2(screenBounds.y * -2, Random.Range(-screenBounds.x, screenBounds.x)); } IEnumerator asteroidWave() { while (true) { yield return new WaitForSeconds(respawnTime); spawnEnemy(); } } } ,Hello, I'm programming a Spaceshooter game and I'm basically done but the only problem is that my gameobject (Asteroids) are not spawning randomly , they are spawning just in one line and i want them how i already said spawning randomly. This is the code im using thank you for helping<3 (Using C#). `using System.Collections; using System.Collections.Generic; using UnityEngine; public class deployAsteroids : MonoBehaviour { public GameObject asteroidPrefab; public float respawnTime = 1.0f; private Vector2 screenBounds; // Use this for initialization void Start() { screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.height, Screen.width, Camera.main.transform.position.z)); StartCoroutine(asteroidWave()); } private void spawnEnemy() { GameObject a = Instantiate(asteroidPrefab) as GameObject; a.transform.position = new Vector2(screenBounds.y * -2, Random.Range(-screenBounds.x, screenBounds.x)); } IEnumerator asteroidWave() { while (true) { yield return new WaitForSeconds(respawnTime); spawnEnemy(); } } }`

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>