Particle System stars script command calls are obsolete. How do I fix this or call the particles the right way. I use unity 2018.3 right now.
using System; using System.Collections; using System.Collections.Generic; using UnityEngine.ParticleSystemModule using UnityEngine; /* using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public float hSliderValue = 1.0F;
void Start()
{
ps = GetComponent<ParticleSystem>();
}
void Update()
{
var main = ps.main;
main.startSize = hSliderValue;
}
void OnGUI()
{
hSliderValue = GUI.HorizontalSlider(new Rect(25, 45, 100, 30), hSliderValue, 0.0F, 10.0F);
}
}*/ public class InfiniteStarfield : MonoBehaviour {
private ParticleSystem.Particle[] points;
public ParticleSystem.MinMaxCurve startSize;
public float hSliderValue = 8.0F;
public ParticleSystem.MinMaxGradient startColor;
public float hSliderValueR = 0.0F;
public float hSliderValueG = 0.0F;
public float hSliderValueB = 0.0F;
public float hSliderValueA = 1.0F;
private ParticleSystem ps;
private Transform tx;
public int starsMax = 600;
public float starSize = .35f;
public float starDistance = 60f;
private float starDistanceSqr = 10f;
private float starClipDistnacesqr = 15f;
public Color starColor;
// Start is called before the first frame update
void Start()
{
GetComponent<ParticleSystem>().SetParticles(points, points.Length);
tx = GetComponent<Transform>();
ps = tx.GetComponent<ParticleSystem>();
starDistanceSqr = starDistance * starDistance;
starClipDistnacesqr = starClipDistnacesqr * starClipDistnacesqr;
}
// Update is called once per frame
void Update()
{
var main = ps.main;
main.startSize = hSliderValue;
main.startColor = new Color(hSliderValueR, hSliderValueG, hSliderValueB, hSliderValueA);
ps.SetParticles(points, points.Length);
if (ps == null) CreateStars();
for (int i = 0; i < starsMax; i++)
{
if ((points[i].position - tx.position).sqrMagnitude > starDistanceSqr)
{
points[i].position = (UnityEngine.Random.insideUnitSphere * starDistanceSqr) + tx.position;
points[i].color = new Color(1, 1, 1, 1);
}
if ((points[i].position - tx.position).sqrMagnitude <= starDistanceSqr)
{
float cap = (points[i].position - tx.position).sqrMagnitude / starClipDistnacesqr;
}
}
GetComponent<ParticleSystem>().SetParticles(points, points.Length);
}
/* void OnGUI() { hSliderValue = GUI.HorizontalSlider(new Rect(25, 45, 100, 30), hSliderValue, 0.0F, 10.0F); GUI.Label(new Rect(25, 40, 100, 30), "Red"); GUI.Label(new Rect(25, 70, 100, 30), "Green"); GUI.Label(new Rect(25, 100, 100, 30), "Blue"); GUI.Label(new Rect(25, 130, 100, 30), "Alpha");
hSliderValueR = GUI.HorizontalSlider(new Rect(95, 45, 100, 30), hSliderValueR, 0.0F, 1.0F);
hSliderValueG = GUI.HorizontalSlider(new Rect(95, 75, 100, 30), hSliderValueG, 0.0F, 1.0F);
hSliderValueB = GUI.HorizontalSlider(new Rect(95, 105, 100, 30), hSliderValueB, 0.0F, 1.0F);
hSliderValueA = GUI.HorizontalSlider(new Rect(95, 135, 100, 30), hSliderValueA, 0.0F, 1.0F);
}
private void CreateStars() { points = new ParticleSystem.[starsMax]; for (int i = 0; i < starsMax; i++) { points[i].position = UnityEngine.Random.insideUnitSphere * starDistanceSqr + tx.position; points[i].size = starSize; points[i].color = new Color(1, 1, 1, 1); } } }
It tells you how to fix the problems in the obsolete message.
Your answer
Follow this Question
Related Questions
Some question about ParticleSystem.emit() rendering 0 Answers
Can I shoot a ray from a particle that hit a collider? 1 Answer
Particles disappear when the parent rotates,My particles disappear when the parent rotates 0 Answers
Why can I not add my own image to particle material? 1 Answer
Are there any disadvantages to using the legacy Ellipsoid Particle System in Unity 5 over Shuriken. 0 Answers