ludumdare50/Assets/Scripts/MinionThrower.cs
Yann Dupont 01 5845572062 Throw start
2022-04-02 02:00:40 -04:00

43 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class MinionThrower : MonoBehaviour {
public GameObject aimArrow;
bool isInThrowMode;
Vector2 throwDirection = Vector2.right;
MinionBar minionBar;
void Awake() {
minionBar = FindObjectOfType<MinionBar>();
}
public void ToggleThrowMode(InputAction.CallbackContext context) {
print("a " + context.phase.ToString());
if(context.performed) {
isInThrowMode = true;
} else if(context.canceled) {
PerformThrow();
isInThrowMode = false;
}
}
public void AimThrow(InputAction.CallbackContext context) {
print("b " + context.ReadValue<Vector2>().ToString());
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
}
}