2025-07-11 15:42:48 +05:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class ButterflySpawner : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject butterflyPrefab;
|
|
|
|
public int spawnDepth = 10; // Distance from camera if needed
|
|
|
|
|
|
|
|
public void SpawnButterflies(int count)
|
|
|
|
{
|
|
|
|
Camera cam = Camera.main;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
Vector3 viewportPos = new Vector3(
|
2025-07-15 22:16:23 +05:00
|
|
|
Random.Range(0.3f, 0.7f), // X: inside screen bounds
|
|
|
|
Random.Range(0.5f, 0.7f), // Y: avoid too low/high
|
2025-07-11 15:42:48 +05:00
|
|
|
spawnDepth // Z: depth from camera
|
|
|
|
);
|
|
|
|
|
|
|
|
Vector3 worldPos = cam.ViewportToWorldPoint(viewportPos);
|
|
|
|
worldPos.z = 0f; // Force Z to 0 if you're working in 2D
|
|
|
|
|
|
|
|
Instantiate(butterflyPrefab, worldPos, Quaternion.identity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|