ludumdare50/Assets/Scripts/MinionThrower.cs
2022-04-02 10:06:38 -04:00

51 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class MinionThrower : MonoBehaviour {
public GameObject[] minionPrefabs;
public GameObject aimArrow;
bool isInThrowMode;
Vector2 throwDirection = Vector2.right;
MinionBar minionBar;
void Awake() {
minionBar = FindObjectOfType<MinionBar>();
aimArrow.SetActive(false);
}
void Start() {
foreach (GameObject minion in minionPrefabs) {
minionBar.AddMinionType(minion);
}
}
public void ToggleThrowMode(InputAction.CallbackContext context) {
if (context.performed) {
isInThrowMode = true;
aimArrow.SetActive(true);
} else if (context.canceled) {
PerformThrow();
isInThrowMode = false;
aimArrow.SetActive(false);
}
}
public void AimThrow(InputAction.CallbackContext context) {
throwDirection = context.ReadValue<Vector2>().normalized;
aimArrow.transform.rotation = Quaternion.FromToRotation(transform.right, throwDirection);
}
void PerformThrow() {
if (!isInThrowMode) {
return;
}
GameObject newMinion = Instantiate(minionBar.GetCurrentMinion(), transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f, Quaternion.identity);
// Apply throw force
}
}