Question by
unity_iN7PWONs9N7Nwg · Feb 10, 2019 at 09:48 PM ·
c#2d2d game2d spritesspawner
I can't get my spawner to work! pls help fast.
Hello. i'm new to programming and i am trying to program a simple dodge game. i can't get my spawner to work an i dont no why. 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();
}
}
}
Comment
try replacing GameObject a = Instantiate(WaterdropPrefab) as GameObject; a.transform.position = new Vector2(screenBounds.x -2, Random.Range(-screenBounds.y, screenBounds.y)); with Instantiate(WaterdropPrefab, new Vector3(screenBounds.x -2, Random.Range(-screenBounds.y, screenBounds.y),0))
Your answer
Follow this Question
Related Questions
I can’t really get the spawner working. 0 Answers
KillPlayer, Null Reference Exception. 2 Answers
Issues with 2D collision/overlap detection,Help detecting 2D collision/overlap 0 Answers
Rhythm game LONG NOTES 0 Answers
How to make an enemy 2d chasing player? 2 Answers