Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Spawner : MonoBehaviour
  6. {
  7. public Material material; // make sure to set this in the unity editor!
  8.  
  9. float timeLastSpawned;
  10. public float spawnRate; // set this in unity editor!!!
  11.  
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15.  
  16. for (int i = 0; i < 10; i++)
  17. {
  18. GameObject o = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  19.  
  20. MeshRenderer meshRenderer = o.GetComponent<MeshRenderer>();
  21. meshRenderer.material = material;
  22.  
  23. o.transform.position = new Vector3();
  24.  
  25. float scale = Random.Range(0.5f, 10.0f);
  26. o.transform.localScale = new Vector3(scale, scale, scale);
  27.  
  28. }
  29. }
  30.  
  31. // Update is called once per frame
  32. void Update()
  33. {
  34. float timeElapsed = Time.time - timeLastSpawned;
  35.  
  36. if (timeElapsed > spawnRate)
  37. {
  38. GameObject o = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  39.  
  40. MeshRenderer meshRenderer = o.GetComponent<MeshRenderer>();
  41. meshRenderer.material = material;
  42.  
  43. // TODO: actually randomly set the position using Random.Range or something
  44. o.transform.position = new Vector3();
  45.  
  46. float scale = Random.Range(0.5f, 10.0f);
  47. o.transform.localScale = new Vector3(scale, scale, scale);
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement