Newer
Older
HardPoint-Project-Abertay-University-Unity3D / Assets / Scripts / CharacterClasses / RogueClass.cs
@Rackday Rackday on 18 Aug 2024 2 KB Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. [CreateAssetMenu(menuName = "Classes/Rogue")]
  6. public class RogueClass:ClassBaseType
  7. {
  8. //Variables
  9. [SerializeField]private float rocketBootsSpeed;
  10. [SerializeField]private float refillSpeed; //One of this should be upgradable
  11. [SerializeField]private float drainSpeed; //One of this should be upgradable
  12. private IMovable movable;
  13. public float fuel;
  14. public float maxFuel; //Upgradable
  15. Rigidbody rb;
  16. SoundsManager soundsManager;
  17. AudioSource audioSource;
  18. [SerializeField]
  19. private string controlKey;
  20. public override void Starter(GameObject source)
  21. {
  22. //base.Starter(source);
  23. dead = false;
  24. currentHp = hp;
  25. rb = source.GetComponent<Rigidbody>();
  26. movable = source.GetComponent<IMovable>();
  27. GameObject t = GameObject.Find("AudioManager");
  28. if(t) soundsManager = t.GetComponent<SoundsManager>();
  29. audioSource = source.GetComponent<AudioSource>();
  30. }
  31. public override void Cooldown()
  32. {
  33. if (fuel < 100)
  34. {
  35. if (movable.OnGround())
  36. {
  37. fuel += refillSpeed * Time.deltaTime;
  38. fuel = Mathf.Clamp(fuel, 0f, maxFuel);
  39. }
  40. }
  41. else fuel = 100;
  42. }
  43. public override void Ability(StatusEffects se)
  44. {
  45. if (Input.GetButton(controlKey))
  46. {
  47. if (fuel > 0)
  48. {
  49. fuel -= drainSpeed * Time.deltaTime;
  50. fuel = Mathf.Clamp(fuel, 0f, Mathf.Infinity);
  51. if (soundsManager)
  52. {
  53. if(!soundsManager.IsPlaying(audioSource))
  54. soundsManager.PlaySoundEffect("Rocket Boots", audioSource);
  55. }
  56. rb.velocity = new Vector3(0, rocketBootsSpeed, 0);
  57. }
  58. else
  59. {
  60. if(soundsManager) soundsManager.StopCurrentSound(audioSource);
  61. }
  62. }
  63. }
  64. }