Newer
Older
HardPoint-Project-Abertay-University-Unity3D / Assets / Scripts / Boss / BossScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BossScript : MonoBehaviour, IUpdatable
{
    // Start is called before the first frame update
    [SerializeField] List<HealthSystem> roomEnemies;
    [SerializeField] List<ParticleSystem> particles;

    bool dead = false;
    float timer= 0f;
    [SerializeField] float timeBeforeGoingToScene;
    [SerializeField] int winingScene;

    [SerializeField] private GameObject canvas;

    SceneMan s;
    bool canvasOn = false;

    SoundsManager soundManager;
    AudioSource audioSource;
    private void Start()
    {
        audioSource = GetComponent<AudioSource>();
        GameObject t = GameObject.Find("AudioManager");
        if(t)
        soundManager = t.GetComponent<SoundsManager>();
        s = GameObject.Find("SceneManager").GetComponent<SceneMan>();
    }
    public void OnDeath()
    {
        if (soundManager) soundManager.PlaySoundEffect("Explosion", audioSource);
        canvas.SetActive(false);
        dead = true; 
        foreach (HealthSystem e in roomEnemies)
        {
            e.Die();
        }
        foreach(ParticleSystem p in particles)
        {
            p.Play();
        }
        timer = timeBeforeGoingToScene;

    }

    public void Updating()
    {
        if (!canvasOn)
        {
            if(canvas) canvas.SetActive(true);
            canvasOn = true;
        }
        if (dead)
        {
            timer -= Time.deltaTime;
            if(timer <= 0)
            {
                s.ChangeScene(winingScene);
            }
        }
    }
}