Newer
Older
HardPoint-Project-Abertay-University-Unity3D / Assets / Scripts / CharacterClasses / RogueClass.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[CreateAssetMenu(menuName = "Classes/Rogue")]
public class RogueClass:ClassBaseType
{

    //Variables
    [SerializeField]private float rocketBootsSpeed;
    [SerializeField]private float refillSpeed; //One of this should be upgradable
    [SerializeField]private float drainSpeed; //One of this should be upgradable
    private IMovable movable;

    public float fuel;
    public float maxFuel; //Upgradable

    Rigidbody rb;

    SoundsManager soundsManager;

    AudioSource audioSource;

    [SerializeField]
    private string controlKey;


    public override void Starter(GameObject source)
    {
        //base.Starter(source);
        dead = false;
        currentHp = hp;
        rb = source.GetComponent<Rigidbody>();
        movable = source.GetComponent<IMovable>();
        GameObject t = GameObject.Find("AudioManager");
        if(t) soundsManager = t.GetComponent<SoundsManager>();
        audioSource = source.GetComponent<AudioSource>();
    }

    public override void Cooldown()
    {
        if (fuel < 100)
        {
            if (movable.OnGround())
            {
                fuel += refillSpeed * Time.deltaTime;
                fuel = Mathf.Clamp(fuel, 0f, maxFuel);
            }
        }
        else fuel = 100;
    }

    public override void Ability(StatusEffects se)
    {
        if (Input.GetButton(controlKey))
        {
            if (fuel > 0)
            {

                fuel -= drainSpeed * Time.deltaTime;
                fuel = Mathf.Clamp(fuel, 0f, Mathf.Infinity);
                if (soundsManager)
                {
                    if(!soundsManager.IsPlaying(audioSource))
                    soundsManager.PlaySoundEffect("Rocket Boots", audioSource);
                }

                rb.velocity = new Vector3(0, rocketBootsSpeed, 0);
            }
            else
            {
                if(soundsManager) soundsManager.StopCurrentSound(audioSource);
            }
        }
    }
}