using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawing : MonoBehaviour
{
public GameObject enemy;
public float respawnTime = 1.0f;
private Vector2 screenBounds;
// Use this for initialization
void Start()
{
screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
StartCoroutine(enemySpawning());
}
// Spawns Enemys every one second.
private void spawnEnemy()
{
GameObject enemyClone = Instantiate(enemy) as GameObject;
enemyClone.transform.position = new Vector2(Random.Range(-screenBounds.x * 2, screenBounds.x * 2), Random.Range(-screenBounds.y * 2, screenBounds.y * 2));
}
// Starts spawning when game starts.
IEnumerator enemySpawning()
{
while (true)
{
yield return new WaitForSeconds(respawnTime);
spawnEnemy();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHitbox : MonoBehaviour
{
public GameObject enemy;
private PlayerInfo playerInfo;
void Start()
{
playerInfo = this.GetComponent<PlayerInfo>();
}
// Destorys enemy
private void OnTriggerEnter2D(Collider2D other)
{
playerInfo.plasmaAmount += 1;
Destroy(enemy);
}
}