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.4 KiB

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;
private float time;
public enum YeetState { Unheld, Held, Yeeting };
public YeetState yeetState { get; private set; } = YeetState.Unheld;
private GameObject _child;
public void Hold(GameObject child)
{
_child = child;
_child.transform.parent = parent.transform;
yeetState = YeetState.Held;
}
public void Yeet()
{
_child.transform.parent = null;
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;
}
}
}