Skip to content

Instantly share code, notes, and snippets.

View curious-username's full-sized avatar

Ben-Jammin curious-username

View GitHub Profile
@curious-username
curious-username / powerup.cs
Last active September 23, 2021 02:09
managing powerups
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUp : MonoBehaviour
{
[SerializeField]
private float _speed = 3.0f;
[SerializeField]
private int _powerupID;
@curious-username
curious-username / LaserFire.cs
Created October 3, 2021 02:16
enemy fire coroutine
IEnumerator LaserFire()
{
var _randomFire = Random.Range(5f, 7f);
Instantiate(_EnemyLaserPrefab, transform.position, Quaternion.identity);
yield return new WaitForSeconds(_randomFire);
}
@curious-username
curious-username / Enemy_Laser.cs
Created October 3, 2021 02:30
enemy laser script
void Update()
{
CalculateMovement();
}
void CalculateMovement()
{
transform.Translate(Vector3.down * _speed * Time.deltaTime);
}
@curious-username
curious-username / enemyLaserGarbageCollection.cs
Created October 3, 2021 02:34
enemy laser garbage collection
if(transform.position.y < -5f)
{
Destroy(gameObject);
}
@curious-username
curious-username / enemyFireInteraction.cs
Created October 3, 2021 02:38
enemy fire interaction
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)
@curious-username
curious-username / player.cs
Last active October 14, 2021 01:09
player ammo code
private int _ammoCount = 15;
[SerializeField]
AudioSource _ammoEmpty
void Update()
{
CalculateMovement();
if (Input.GetKeyDown(KeyCode.Space))
{
@curious-username
curious-username / uimanager.cs
Last active October 14, 2021 01:33
text system for space shooter
[SerializeField]
private Text _ammoCount;
void Start()
{
_ammoCount.text = "Ammo: " + 15;
}
public void UpdateAmmoCount(int ammo)
{
_ammoCount.text = "Ammo: " + ammo.ToString();
@curious-username
curious-username / powerup.cs
Created October 14, 2021 01:36
ammo powerup
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Player player = other.GetComponent<Player>();
if (player != null)
{
//if powerUp ID is 0
@curious-username
curious-username / spawnmanager.cs
Created October 14, 2021 01:40
updating the spawn manager
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));
@curious-username
curious-username / coutdown.cs
Last active October 16, 2021 04:12
count down timer
private float _countDown = 3;
IEnumerator CountDown()
{
while(_countDown > 0)
{
yield return new WaitForSeconds(1.0f);
_countDown--;
}
_rateOverTimeValue = 0;