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. private float time;
  10. public enum YeetState { Unheld, Held, Yeeting };
  11. public YeetState yeetState { get; private set; } = YeetState.Unheld;
  12. private GameObject _child;
  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. yeetState = YeetState.Yeeting;
  23. time = yeetDuration;
  24. }
  25. // Start is called before the first frame update
  26. void Start()
  27. {
  28. }
  29. // Update is called once per frame
  30. void Update()
  31. {
  32. switch(yeetState)
  33. {
  34. case YeetState.Yeeting:
  35. _child.transform.position += _child.transform.forward * yeetVelocity * Time.deltaTime;
  36. time -= Time.deltaTime;
  37. if(time <= 0f)
  38. {
  39. yeetState = YeetState.Unheld;
  40. }
  41. break;
  42. case YeetState.Held:
  43. break;
  44. case YeetState.Unheld:
  45. _child = null;
  46. break;
  47. }
  48. }
  49. }