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.

61 lines
1.6 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class YeetController : MonoBehaviour
  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. _child.GetComponent<Rigidbody>().velocity = _child.transform.forward * yeetVelocity;
  24. yeetState = YeetState.Yeeting;
  25. _time = yeetDuration;
  26. }
  27. // Start is called before the first frame update
  28. void Start()
  29. {
  30. }
  31. // Update is called once per frame
  32. void Update()
  33. {
  34. switch(yeetState)
  35. {
  36. case YeetState.Yeeting:
  37. //_child.transform.position += _child.transform.forward * yeetVelocity * Time.deltaTime;
  38. _time -= Time.deltaTime;
  39. if(_time <= 0f)
  40. {
  41. Debug.Log("YeetController.Update: Yeet finished");
  42. yeetState = YeetState.Unheld;
  43. }
  44. break;
  45. case YeetState.Held:
  46. break;
  47. case YeetState.Unheld:
  48. _child = null;
  49. break;
  50. }
  51. }
  52. }