Files
Gameshit/GOAP/Assets/Scrips/AI_Area.cs
2025-05-31 15:54:23 +02:00

35 lines
1009 B
C#

using UnityEngine;
[ExecuteInEditMode]
public class AI_Area : MonoBehaviour
{
[Header("Area Settings")]
public Vector2 size = new Vector2(10f, 10f); // Width x Depth
public Color gizmoColor = new Color(0f, 1f, 0f, 0.25f);
public Vector3 GetRandomPointInArea()
{
float halfX = size.x / 2f;
float halfZ = size.y / 2f;
float randomX = Random.Range(-halfX, halfX);
float randomZ = Random.Range(-halfZ, halfZ);
Vector3 localOffset = new Vector3(randomX, 0f, randomZ);
return transform.position + transform.rotation * localOffset;
}
void OnDrawGizmos()
{
Gizmos.color = gizmoColor;
Matrix4x4 oldMatrix = Gizmos.matrix;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawCube(Vector3.zero, new Vector3(size.x, 0.01f, size.y));
Gizmos.matrix = oldMatrix;
Gizmos.color = Color.green;
Gizmos.DrawWireCube(transform.position, new Vector3(size.x, 0.01f, size.y));
}
}