Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class popSpheres : MonoBehaviour {
- public int nbSpheres = 1000;
- public Vector3 maxBounds = new Vector3(100f,100f,100);
- public Vector3 minBounds = new Vector3(-100f,-100f,0f);
- private List<GameObject> spheres;
- public Material sphereMat;
- public float velocMax=0.5f;
- public float velocMin=0.1f;
- private List<float> velocities;
- private List<Vector3> directions;
- private float time = 0.0f;
- // Use this for initialization
- void Start () {
- if(sphereMat == null)
- sphereMat = new Material(Shader.Find("Standard"));
- spheres = new List<GameObject>(nbSpheres);
- velocities = new List<float>(nbSpheres);
- directions = new List<Vector3>(nbSpheres);
- for(int i=0;i<nbSpheres;i++){
- GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
- spheres.Add(sphere);
- Renderer sr = sphere.GetComponent<Renderer>();
- sr.sharedMaterial = sphereMat;
- sr.motionVectors = false;
- sr.receiveShadows = false;
- sr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
- sphere.transform.position = new Vector3 (Random.Range(minBounds.x,maxBounds.x),Random.Range(minBounds.y,maxBounds.y),Random.Range(minBounds.z,maxBounds.z));
- sphere.transform.parent = transform;
- sphere.transform.name = sphere.transform.name+"_"+i;
- velocities.Add(Random.Range(velocMin, velocMax));
- directions.Add(new Vector3(Random.Range(-1,1),Random.Range(-1,1 ),Random.Range(-1,1 )).normalized);
- }
- }
- void Update(){
- time += Time.deltaTime;
- for(int i=0;i<nbSpheres;i++){
- spheres[i].transform.position += Time.deltaTime * (directions[i]*velocities[i]);
- }
- //Check bounds ...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement