Boss Spawn Sequence Part 2

Enable and disable scripts from code

Just like in horror movies let’s make our boss move in slowly without attacking. Then the boss will start moving and shooting. In other words move the boss to center of the screen first then start the turrets and movement.

BossMovementStart Script

In Start() we disable the BossHealth script, the BossMovement script and both the turrets.

The variable _target contains the place where we move our spawned boss towards. When it has reached that point or is very close to it we re-enable our scripts and turrets. After re-enabling we disable this script.

private float _speed = 2f;
private Vector3 _target = new Vector3(0, 1.5f, 0);

private BossMovement _bossMove;
private BossHealth _bossHealth;
[SerializeField] private GameObject TurretL;
[SerializeField] private GameObject TurretR;

private void Start()
{
_bossMove = this.GetComponent<BossMovement>();
_bossMove.enabled = false;
_bossHealth = this.GetComponent<BossHealth>();
_bossHealth.enabled = true;

TurretL.SetActive(false);
TurretR.SetActive(false);
}

void Update()
{
transform.position = Vector3.MoveTowards(transform.position, _target, _speed * Time.deltaTime);
if (Vector3.Distance(transform.position, _target) < 0.001f)
{
_bossMove.enabled = true;
TurretL.SetActive(true);
TurretR.SetActive(true);

this.GetComponent<BossMovementStart>().enabled = false;
}
}

Result: Entire Boss Spawn Sequence

Now our Boss spawn sequence looks like this

--

--

--

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.

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

Recommended from Medium

RecyclerView with Compose View is not Performant

A must know secret about Android View State storing mechanism!

Understanding MVVM pattern for Android in 2021

WorkManager in Android

android workmanager

Android Libraries Repository

The Imperfect ‘Send Email’ Action in Android

Android Kotlin Developer Nanodegree Projects Review

Toothpick 3 — a hidden gem

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
Tristan Engel

Tristan Engel

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.

More from Medium

NoColor bug on unfilled objects

DesktopInfo — Conky for Windows

How to regenerate a bitly link for the same long URL?

Setting Up Git with Unity

GitHub Download Page