Question by
unity_iN7PWONs9N7Nwg · Feb 10, 2019 at 09:39 PM ·
c#2d2d gamespawner
I can’t really get the spawner working.
Hello. I’m new to programming and trying to program a simple dodge game. I can’t really get the spawner working. If you can help me it would be very nice. Here is the code.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class WaterDropSpawn : MonoBehaviour {
public GameObject WaterdropPrefab;
public float respawnTime = 1.0f;
private Vector2 screenBounds;
void Start()
{
screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
StartCoroutine(dropWave());
}
private void spawnEnemy()
{
GameObject a = Instantiate(WaterdropPrefab) as GameObject;
a.transform.position = new Vector2(screenBounds.x * -2, Random.Range(-screenBounds.y, screenBounds.y));
}
IEnumerator dropWave()
{
while (true)
{
yield return new WaitForSeconds(respawnTime);
spawnEnemy();
}
}
},using System.Collections; using System.Collections.Generic; using UnityEngine;
public class WaterDropSpawn : MonoBehaviour {
public GameObject WaterdropPrefab;
public float respawnTime = 1.0f;
private Vector2 screenBounds;
void Start()
{
screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
StartCoroutine(dropWave());
}
private void spawnEnemy()
{
GameObject a = Instantiate(WaterdropPrefab) as GameObject;
a.transform.position = new Vector2(screenBounds.x * -2, Random.Range(-screenBounds.y, screenBounds.y));
}
IEnumerator dropWave()
{
while (true)
{
yield return new WaitForSeconds(respawnTime);
spawnEnemy();
}
}
},
Comment
try
screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width/2, Screen.height/2, Camera.main.transform.position.z));
Your answer
Follow this Question
Related Questions
I can't get my spawner to work! pls help fast. 0 Answers
Why won't my 2D Sprite Move? 1 Answer
2D AI movement 0 Answers
Detect whether a Rigidbody collided with a Trigger 2 Answers
Cannot delay player respawn. 2 Answers