34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class TrashSpawner : MonoBehaviour
|
|
{
|
|
// Assign in inspector: the pool of sprites to choose from
|
|
public Sprite[] spritePool;
|
|
[Tooltip("Visual radius for spawn point in editor")]
|
|
public float gizmoRadius = 0.5f;
|
|
|
|
// Visual indicator for editor only
|
|
private void OnDrawGizmos()
|
|
{
|
|
Gizmos.color = Color.cadetBlue;
|
|
Gizmos.DrawWireSphere(transform.position, gizmoRadius);
|
|
|
|
// Draw a cross in the center for better visibility
|
|
Gizmos.DrawLine(
|
|
transform.position + Vector3.left * gizmoRadius * 0.5f,
|
|
transform.position + Vector3.right * gizmoRadius * 0.5f);
|
|
Gizmos.DrawLine(
|
|
transform.position + Vector3.up * gizmoRadius * 0.5f,
|
|
transform.position + Vector3.down * gizmoRadius * 0.5f);
|
|
}
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
var sr = GetComponent<SpriteRenderer>();
|
|
if (spritePool != null && spritePool.Length > 0 && sr != null)
|
|
{
|
|
sr.sprite = spritePool[Random.Range(0, spritePool.Length)];
|
|
}
|
|
}
|
|
}
|