using System.Collections; using System.Collections.Generic; using UnityEngine; public class Staff : MonoBehaviour, IWeapon { [SerializeField] private WeaponInfo weaponInfo; // Information about the staff weapon [SerializeField] private GameObject magicLaser; // Prefab for the magic laser projectile [SerializeField] private Transform magicLaserSpawnPoint; // Spawn point for the magic laser private Animator myAnimator; // Reference to the Animator component readonly int ATTACK_HASH = Animator.StringToHash("Attack"); // Hash for the attack animation trigger private void Awake() { myAnimator = GetComponent(); // Get the Animator component attached to this GameObject } private void Update() { MouseFollowWithOffset(); // Update weapon rotation to follow the mouse with an offset } public void Attack() { myAnimator.SetTrigger(ATTACK_HASH); // Trigger the attack animation } // Animation event to spawn the magic laser projectile public void SpawnStaffProjectileAnimEvent() { GameObject newLaser = Instantiate(magicLaser, magicLaserSpawnPoint.position, Quaternion.identity); // Create a new magic laser newLaser.GetComponent().UpdateLaserRange(weaponInfo.weaponRange); // Set the laser's range based on weapon info } public WeaponInfo GetWeaponInfo() { return weaponInfo; // Return the weapon info } // Helper method to rotate the weapon to follow the mouse cursor with an offset private void MouseFollowWithOffset() { Vector3 mousePos = Input.mousePosition; // Get the mouse position on the screen Vector3 playerScreenPoint = Camera.main.WorldToScreenPoint(PlayerController.Instance.transform.position); // Convert player position to screen coordinates float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg; // Calculate the angle between the player and mouse cursor // Rotate the weapon based on the mouse position relative to the player if (mousePos.x < playerScreenPoint.x) { ActiveWeapon.Instance.transform.rotation = Quaternion.Euler(0, -180, angle); // Rotate weapon when facing left } else { ActiveWeapon.Instance.transform.rotation = Quaternion.Euler(0, 0, angle); // Rotate weapon when facing right } } }