using UnityEngine; public class Weapon : MonoBehaviour { public enum HitShape { Sphere, Box } [Header("Combat Stats")] public float damage = 10f; [Header("Hit Detection")] public HitShape hitShape = HitShape.Sphere; [Tooltip("Used if HitShape is Sphere")] public float attackRadius = 1.0f; [Tooltip("Used if HitShape is Box (represents half the size of the box on X, Y, Z)")] public Vector3 hitBoxHalfExtents = new Vector3(0.5f, 0.5f, 1f); [Tooltip("Optional: Drag a child GameObject here to act as the center of the hit shape. If left empty, uses the weapon's base transform.")] public Transform hitCenter; [Header("Equip Offsets")] public Vector3 equippedPositionOffset = Vector3.zero; public Vector3 equippedRotationOffset = Vector3.zero; [Header("Unequip Offsets")] public Vector3 unequippedPositionOffset = Vector3.zero; public Vector3 unequippedRotationOffset = Vector3.zero; /// /// Gets the world position where hit detection should occur. /// public Vector3 GetHitCenter() { if (hitCenter != null) { return hitCenter.position; } return transform.position; } /// /// Gets the world rotation for box cast alignment. /// public Quaternion GetHitRotation() { if (hitCenter != null) { return hitCenter.rotation; } return transform.rotation; } private void OnDrawGizmosSelected() { Gizmos.color = Color.red; Vector3 center = GetHitCenter(); if (hitShape == HitShape.Sphere) { Gizmos.DrawWireSphere(center, attackRadius); } else if (hitShape == HitShape.Box) { // Gizmos.DrawWireCube does not support rotation natively, so we modify the Gizmo matrix Matrix4x4 oldMatrix = Gizmos.matrix; Gizmos.matrix = Matrix4x4.TRS(center, GetHitRotation(), Vector3.one); Gizmos.DrawWireCube(Vector3.zero, hitBoxHalfExtents * 2f); Gizmos.matrix = oldMatrix; } } }