This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PowerUp : MonoBehaviour | |
{ | |
[SerializeField] | |
private float _speed = 3.0f; | |
[SerializeField] | |
private int _powerupID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerator LaserFire() | |
{ | |
var _randomFire = Random.Range(5f, 7f); | |
Instantiate(_EnemyLaserPrefab, transform.position, Quaternion.identity); | |
yield return new WaitForSeconds(_randomFire); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Update() | |
{ | |
CalculateMovement(); | |
} | |
void CalculateMovement() | |
{ | |
transform.Translate(Vector3.down * _speed * Time.deltaTime); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(transform.position.y < -5f) | |
{ | |
Destroy(gameObject); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Player _player; | |
private float _speed = 8f; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
_player = GameObject.Find("Player").GetComponent<Player>(); | |
} | |
private void OnTriggerEnter2D(Collider2D collision) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int _ammoCount = 15; | |
[SerializeField] | |
AudioSource _ammoEmpty | |
void Update() | |
{ | |
CalculateMovement(); | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SerializeField] | |
private Text _ammoCount; | |
void Start() | |
{ | |
_ammoCount.text = "Ammo: " + 15; | |
} | |
public void UpdateAmmoCount(int ammo) | |
{ | |
_ammoCount.text = "Ammo: " + ammo.ToString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void OnTriggerEnter2D(Collider2D other) | |
{ | |
if (other.tag == "Player") | |
{ | |
Player player = other.GetComponent<Player>(); | |
if (player != null) | |
{ | |
//if powerUp ID is 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerator SpawnPowerupRoutine() | |
{ | |
//every 3 - 7 seconds, spawn in a powerup | |
while (_stopSpawning == false) { | |
Vector3 spawn = new Vector3(Random.Range(-8f, 8f), 7, 0); | |
int randomPowerUp = Random.Range(0, 4); | |
Instantiate(_powerups[randomPowerUp], spawn, Quaternion.identity); | |
yield return new WaitForSeconds(Random.Range(3, 8)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private float _countDown = 3; | |
IEnumerator CountDown() | |
{ | |
while(_countDown > 0) | |
{ | |
yield return new WaitForSeconds(1.0f); | |
_countDown--; | |
} | |
_rateOverTimeValue = 0; |