ludumdare50/Assets/Scripts/MinionThrower.cs
Yann Dupont 01 c428a0e96f Throw start
2022-04-02 01:34:50 -04:00

42 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class MinionThrower : MonoBehaviour {
public GameObject placeholderMinionPrefab;
public GameObject aimArrow;
bool isInThrowMode;
Vector2 throwDirection = Vector2.right;
MinionBar minionBar;
void Awake() {
minionBar = FindObjectOfType<MinionBar>();
}
public void ToggleThrowMode(InputAction.CallbackContext context) {
if(context.performed) {
isInThrowMode = true;
} else if(context.canceled) {
PerformThrow();
isInThrowMode = false;
}
}
public void AimThrow(InputAction.CallbackContext context) {
throwDirection = context.ReadValue<Vector2>().normalized;
}
void PerformThrow() {
if(!isInThrowMode) {
return;
}
Object currentMinion = minionBar.GetCurrentMinion();
GameObject newMinion = Instantiate(placeholderMinionPrefab, transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f, Quaternion.identity);
}
}