mirror of
https://github.com/ConjureETS/PixelSphinx.git
synced 2026-03-24 02:20:58 +00:00
random spawn around a circle
This commit is contained in:
parent
8b8de8b58a
commit
8a25f480ae
@ -4,10 +4,16 @@ using System.Collections;
|
|||||||
public class SpawnAsteroids : MonoBehaviour {
|
public class SpawnAsteroids : MonoBehaviour {
|
||||||
|
|
||||||
public GameObject myAsteroid;
|
public GameObject myAsteroid;
|
||||||
public Vector3 initialPosition;
|
Vector3 center;
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float d;
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start()
|
||||||
|
{
|
||||||
|
center = new Vector3(0, 0);
|
||||||
|
d = 4;
|
||||||
InvokeRepeating("Spawn", 0, 0.5F);
|
InvokeRepeating("Spawn", 0, 0.5F);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -20,6 +26,16 @@ public class SpawnAsteroids : MonoBehaviour {
|
|||||||
void Spawn()
|
void Spawn()
|
||||||
{
|
{
|
||||||
GameObject instance = Instantiate(myAsteroid);
|
GameObject instance = Instantiate(myAsteroid);
|
||||||
instance.transform.position = new Vector3(10, 10, 0);
|
instance.transform.position = getPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 getPositions()
|
||||||
|
{
|
||||||
|
float theta = Random.Range(0F, 360F);
|
||||||
|
x = center.x - Mathf.Sin(theta) * d;
|
||||||
|
y = center.y - Mathf.Cos(theta) * d;
|
||||||
|
return new Vector3(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user