Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- [RequireComponent(typeof(Camera))]
- public class Attractor : MonoBehaviour
- {
- void Start()
- {
- if(generateFromArray)
- {
- int colorLen = colors.Length;
- float toStop = 1.0f / colorLen;
- GradientColorKey[] colorKeys = new GradientColorKey[colorLen];
- for(int i = 0; i < colorLen; ++i)
- {
- float stop = (i + 1) * toStop;
- colorKeys[i] = new GradientColorKey(colors[i], stop);
- }
- gradient = new Gradient();
- gradient.SetKeys(colorKeys, alphaKeys);
- gradient.mode = gradientMode;
- }
- cam = GetComponent<Camera>();
- Mesh mesh = P5.Cube();
- movers = new Rigidbody[moverCount];
- for(int i = 0; i < moverCount; ++i)
- {
- string name = string.Format("Mover {0:D3}", i);
- GameObject mover = new GameObject(name);
- Rigidbody body= mover.AddComponent<Rigidbody>();
- body.useGravity = false;
- float m = Random.Range(minMass, maxMass);
- body.mass = m;
- movers[i] = body;
- Transform tr = mover.transform;
- float s = P5.Map(m, minMass, maxMass, maxScale, minScale);
- tr.localScale = new Vector3(s, s, s);
- tr.localPosition = initialSpread * Random.insideUnitSphere;
- MeshFilter mf = mover.AddComponent<MeshFilter>();
- mf.sharedMesh = mesh;
- Material material = new Material(sourceMaterial);
- material.color = gradient.Evaluate(P5.Map(m, minMass, maxMass));
- MeshRenderer mr = mover.AddComponent<MeshRenderer>();
- mr.sharedMaterial = material;
- if(addColliders)
- {
- mover.AddComponent<BoxCollider>();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment