|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class YeetController : MonoBehaviour
- {
- public GameObject parent { get; set; }
-
- public float yeetVelocity = 10f;
- public float yeetDuration = 2f;
-
- public enum YeetState { Unheld, Held, Yeeting };
- public YeetState yeetState { get; private set; } = YeetState.Unheld;
-
- private GameObject _child;
- private float _time;
-
- private GameObject m_child;
- private GameObject m_body;
-
- private void Awake()
- {
- m_body = this.gameObject;
- }
-
- public void Hold(GameObject child)
- {
- _child = child;
- _child.transform.parent = parent.transform;
- yeetState = YeetState.Held;
- }
-
- public void Yeet()
- {
- _child.transform.parent = null;
- _child.transform.rotation = parent.transform.rotation;
- _child.GetComponent<Rigidbody>().velocity = _child.transform.forward * yeetVelocity + _child.transform.up * yeetVelocity;
- yeetState = YeetState.Yeeting;
- _time = yeetDuration;
- }
-
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
- switch(yeetState)
- {
- case YeetState.Yeeting:
- //_child.transform.position += _child.transform.forward * yeetVelocity * Time.deltaTime;
- _time -= Time.deltaTime;
-
- if(_time <= 0f)
- {
- Debug.Log("YeetController.Update: Yeet finished");
- yeetState = YeetState.Unheld;
- }
- break;
- case YeetState.Held:
- break;
- case YeetState.Unheld:
- _child = null;
- break;
- }
- }
-
- private void OnTriggerEnter(Collider collider)
- {
- Debug.Log("PlayerInputController.OnTriggerEnter: arrived");
- m_child = collider.gameObject;
- }
-
- private void OnTriggerExit(Collider collider)
- {
- m_child = null;
- }
-
- private void OnYeet()
- {
- parent = m_body;
- switch (yeetState)
- {
- case YeetController.YeetState.Unheld:
- if(m_child)
- Hold(m_child);
- // Grab nearest baby
- break;
- case YeetController.YeetState.Held:
- Yeet();
- // Yeet baby
- break;
- case YeetController.YeetState.Yeeting:
- // Cooldown?
- break;
- }
- }
- }
|