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.
 
 
 
 

62 lines
1.6 KiB

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;
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;
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;
}
}
}