Hello all,
Sorry if this is a basic question but I am very new to C# and Unity and can’t figure this out for the life of me.
Here is the code and problem…
Problem:
For some reason GetParticles always returns 0, even if used in LateUpdate. At the moment I’ve just set the length of the Particle array manually but I would like the script to be able to do it so that my colleagues don’t have to play around with the script each time.
Other problem is I need help making some lines work which keep throwing errors…
Code:
using UnityEngine;
using System.Collections;
public class ParticleAttract : MonoBehaviour
{
public int PullDistance;
public ParticleSystem MagnetPoint;
private Particle[] x = new Particle[50];
private ParticleSystem y;
private Transform t;
private float d;
//Use this for initialization
void Start ()
{
t = transform;
d = PullDistance*PullDistance;
//x = (ParticleSystem)(GameObject.Find(MagnetPoint).GetComponent(typeof(ParticleSystem)));
//x = y.particles;
string p = particleSystem.name;
int o = particleSystem.maxParticles;
Debug.Log(p);
Debug.Log(o);
Debug.Log(x);
}
void Update ()
{
float n;
for(int i = 0; i < x.Length; i++)
{
n = Vector3.SqrMagnitude(t.position - x[i].position);
Debug.Log(d);
if (n < d)
{
x[i].position = Vector3.Lerp(x[i].position, transform.position, Time.deltaTime / 2.0f);
Debug.Log(x[i].position);
}
}
}
}
I need to replace the commented out lines
//x = (ParticleEmitter)(GameObject.Find(MagnetPoint).GetComponent(typeof(ParticleEmitter)));
//x = y.particles;
With something that works.
Compiler errors are:
Line 20- The best overloaded method match for ‘…Find(string)’ has some invalid arguments.
Line 20- Argument #1 cannot convert ‘…’ expression to type ‘string’.
Line 21- ParticleSystem does not contain a definition for ‘particles’ etc etc