Day 44 — Improvements: enemies destroying powerups + powerup collector

if (other.tag == "EnemyLaser")
{
Destroy(other.gameObject);
Destroy(this.gameObject);
}
if (GameObject.Find("Enemy(Clone)") != null)
{
_enemy = GameObject.Find("Enemy(Clone)").GetComponent<Enemy>();
}
else
{
Debug.Log("There are no enemies on screen");
}
if (_enemy != null)
{
float distance = _enemy.transform.position.x - transform.position.x;
if (distance < 0.2f && distance > -0.2f)
{
if (_enemy.transform.position.y > transform.position.y)
{
_enemy.FireLaser();
}
}
}
public void FireLaser()
{
StartCoroutine(FireLaserRoutine());
}
IEnumerator FireLaserRoutine()
{
_canFire = true;
yield return new WaitForSeconds(0.1f);
if (_canFire == true)
{
GameObject enemyLaser = Instantiate(_enemyLaser, transform.position, Quaternion.identity);
Laser[] lasers = enemyLaser.GetComponentsInChildren<Laser>();
for (int i = 0; i < lasers.Length; i++)
{
lasers[i].EnemyLaser();
}
_canFire = false;
}
else
{
Debug.Log("Can't fire");
}
}

Powerup Collector

private _powerupSpeed
if (Input.GetKey(KeyCode.C))
{
GameObject[] _powerups = GameObject.FindGameObjectsWithTag("Powerup");
Transform[] powerupTransform = new Transform[_powerups.Length];
for (int i = 0; i < _powerups.Length; i++)
{
powerupTransform[i] = _powerups[i].transform;
powerupTransform[i].position = Vector3.MoveTowards(powerupTransform[i].position, transform.position, _powerupSpeed * Time.deltaTime);
}
}

--

--

--

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Insights from Full Stack Fest 2019 — 2019.fullstackfest.com

Spring Boot Authentication with VueJS + JWT + Http Only Cookie

Coming at Quality From All Angles: Visualizing our QA Strategy

GitHub vs. GitLab: comparison of the two version control systems

Spring MVC

Speed up Ruby on Rails product

PYTHON IDLE | GETTING STARTED WITH PYTHON #TechBlog

Some of the Most Useful Python Add-ons

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Connor Fullarton

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

More from Medium

Congruency Based Family Governance

THURSDAY, DECEMBER 2, 9:40 — 11:00 | THE AFTERMATH

Migrating operation ‘follow’ from @cloudant/cloudant to @ibm-cloud/cloudant

IncentiBook Relaunch