Global Game Jam 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class YeetController : MonoBehaviour, IYeetable
  5. {
  6. public GameObject parent { get; set; }
  7. public float yeetVelocity = 10f;
  8. public float yeetDuration = 2f;
  9. public enum YeetState { Unheld, Held, Yeeting };
  10. public YeetState yeetState { get; private set; } = YeetState.Unheld;
  11. private GameObject _child;
  12. private float _time;
  13. public void Hold(GameObject child)
  14. {
  15. _child = child;
  16. _child.transform.parent = parent.transform;
  17. yeetState = YeetState.Held;
  18. }
  19. public void Yeet()
  20. {
  21. _child.transform.parent = null;
  22. _child.transform.rotation = parent.transform.rotation;
  23. yeetState = YeetState.Yeeting;
  24. _time = yeetDuration;
  25. }
  26. // Start is called before the first frame update
  27. void Start()
  28. {
  29. }
  30. // Update is called once per frame
  31. void Update()
  32. {
  33. switch(yeetState)
  34. {
  35. case YeetState.Yeeting:
  36. _child.transform.position += _child.transform.forward * yeetVelocity * Time.deltaTime;
  37. _time -= Time.deltaTime;
  38. if(_time <= 0f)
  39. {
  40. yeetState = YeetState.Unheld;
  41. }
  42. break;
  43. case YeetState.Held:
  44. break;
  45. case YeetState.Unheld:
  46. _child = null;
  47. break;
  48. }
  49. }
  50. }