Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Ben-Jammin curious-username

🎯
Focusing
View GitHub Profile
View coutdown.cs
private float _countDown = 3;
IEnumerator CountDown()
{
while(_countDown > 0)
{
yield return new WaitForSeconds(1.0f);
_countDown--;
}
_rateOverTimeValue = 0;
@curious-username
curious-username / spawnmanager.cs
Created Oct 14, 2021
updating the spawn manager
View spawnmanager.cs
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));
View powerup.cs
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 / uimanager.cs
Last active Oct 14, 2021
text system for space shooter
View uimanager.cs
[SerializeField]
private Text _ammoCount;
void Start()
{
_ammoCount.text = "Ammo: " + 15;
}
public void UpdateAmmoCount(int ammo)
{
_ammoCount.text = "Ammo: " + ammo.ToString();
@curious-username
curious-username / player.cs
Last active Oct 14, 2021
player ammo code
View player.cs
private int _ammoCount = 15;
[SerializeField]
AudioSource _ammoEmpty
void Update()
{
CalculateMovement();
if (Input.GetKeyDown(KeyCode.Space))
{
View enemyFireInteraction.cs
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)
View enemyLaserGarbageCollection.cs
if(transform.position.y < -5f)
{
Destroy(gameObject);
}
View Enemy_Laser.cs
void Update()
{
CalculateMovement();
}
void CalculateMovement()
{
transform.Translate(Vector3.down * _speed * Time.deltaTime);
}
View LaserFire.cs
IEnumerator LaserFire()
{
var _randomFire = Random.Range(5f, 7f);
Instantiate(_EnemyLaserPrefab, transform.position, Quaternion.identity);
yield return new WaitForSeconds(_randomFire);
}
@curious-username
curious-username / powerup.cs
Last active Sep 23, 2021
managing powerups
View powerup.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUp : MonoBehaviour
{
[SerializeField]
private float _speed = 3.0f;
[SerializeField]
private int _powerupID;