Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Spawner : MonoBehaviour
- {
- public Material material; // make sure to set this in the unity editor!
- float timeLastSpawned;
- public float spawnRate; // set this in unity editor!!!
- // Start is called before the first frame update
- void Start()
- {
- for (int i = 0; i < 10; i++)
- {
- GameObject o = GameObject.CreatePrimitive(PrimitiveType.Sphere);
- MeshRenderer meshRenderer = o.GetComponent<MeshRenderer>();
- meshRenderer.material = material;
- o.transform.position = new Vector3();
- float scale = Random.Range(0.5f, 10.0f);
- o.transform.localScale = new Vector3(scale, scale, scale);
- }
- }
- // Update is called once per frame
- void Update()
- {
- float timeElapsed = Time.time - timeLastSpawned;
- if (timeElapsed > spawnRate)
- {
- GameObject o = GameObject.CreatePrimitive(PrimitiveType.Sphere);
- MeshRenderer meshRenderer = o.GetComponent<MeshRenderer>();
- meshRenderer.material = material;
- // TODO: actually randomly set the position using Random.Range or something
- o.transform.position = new Vector3();
- float scale = Random.Range(0.5f, 10.0f);
- o.transform.localScale = new Vector3(scale, scale, scale);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement