Quantcast
Viewing latest article 12
Browse Latest Browse All 125

Random Respawn,Random Spawn

Currently, I'm making a shooting game. I want to respawn enemies randomly. This is the code i've made: using System.Collections; using System.Collections.Generic; using UnityEngine; public class RespawnManager : MonoBehaviour { public GameObject obj; public Transform respawnTr; void Start () { StartCoroutine(RespawnEnemy()); } IEnumerator RespawnEnemy () { while (true) { yield return new WaitForSeconds (0.7f); float range = Screen.width / Screen.height * Camera.main.orthographicSize; float random_num = Random.Range (-range, range); Instantiate (obj, respawnTr.position + new Vector3(random_num, 0, 0), Quaternion.identity); } } } However, when I run the program, the enemies just respawns at one place. How should I solve this problem????

Viewing latest article 12
Browse Latest Browse All 125

Trending Articles