using System.Collections; using System.Collections.Generic; using UnityEngine; public class YeetController : MonoBehaviour, IYeetable { 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; 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; 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) { yeetState = YeetState.Unheld; } break; case YeetState.Held: break; case YeetState.Unheld: _child = null; break; } } }