I’m using unity 3d but I am using inside unit CIRCLE because I only want these objects to spawn on the XY plane.
I have this object a player can control and it spawns other objects in a fixed radius around itself which is what I want but sometimes the objects spawn on the player object, this is a problem because then the player object takes damage so basically I want a zone around it where objects wont spawn.
here is what I have right now (as you can see there are errors with Random.Range but without that and with just random.insideunitcircle it works fine with the issues mentioned above)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour {
public GameObject orbiter;
public float distance = 50f;
public float spawnTime = 5f;
public float minDistance = 20f;
// Use this for initialization
void Start () {
Instantiate(orbiter, Random.insideUnitCircle*distance, transform.rotation);
}
// Update is called once per frame
void Update () {
spawnTime -= Time.deltaTime;
if (spawnTime <= 0)
{
Instantiate(orbiter, Random.Range(Random.insideUnitCircle.Normalize * minDistance, Random.insideUnitCircle * distance) , transform.rotation);
spawnTime = 5f;
}
}
}