This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
monsterstalker/Assets/Scripts/MonsterSpawner.cs
T
2018-04-10 23:53:49 +10:00

28 lines
626 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonsterSpawner : MonoBehaviour {
public GameObject monsterPrefab;
public Vector2 motion;
public float delay;
AudioSource audioSource;
void Awake() {
audioSource = GetComponent<AudioSource> ();
StartCoroutine (SpawnMonster ());
}
IEnumerator SpawnMonster() {
while(true) {
yield return new WaitForSeconds (delay);
GameObject monster = Instantiate (monsterPrefab);
monster.transform.position = transform.position;
monster.GetComponent<Rigidbody2D> ().velocity = motion;
audioSource.Play ();
}
}
}