Boss Spawn Sequence Part 2
Enable and disable scripts from code
2 min readAug 2, 2021
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;
}
}