Created
April 26, 2017 03:55
-
-
Save unity3dcollege/71e5fbe514d1e1ef7e0aa3688ba22d9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class AsteroidSpawner : MonoBehaviour | |
{ | |
public int count = 10; | |
public GameObject prefab; | |
private void Start() | |
{ | |
for (int i = 0; i < count; i++) | |
{ | |
var instance = Instantiate(prefab) as GameObject; | |
instance.transform.position = GetRandomPosition(); | |
instance.transform.localScale = GetRandomScale(); | |
} | |
} | |
private Vector3 GetRandomScale() | |
{ | |
float scale = Random.Range(1.2f, 4f); | |
return new Vector3(scale, scale, scale); | |
} | |
private Vector3 GetRandomPosition() | |
{ | |
return new Vector3( | |
Random.Range(-4f, 4f), | |
Random.Range(-4f, 4f), | |
Random.Range(-4f, 4f)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment