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(); 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().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 } }