I want to be able to use a variable from one script in another script. My goal is to allow me to reference the particleScale variable and use it to affect the size of the object connected to the second script. I also ant to later reference other variables from other scripts. There also will be several instances of each object. This is my first script;
public class Particle : MonoBehaviour
{
public float particleSize;
public Transform particle;
void Start()
{
particle.localScale *= particleSize;
}
}
This is my second;
public class Magnetic : MonoBehaviour
{
public Transform magnetic;
void Start()
{
magnetic.localscale *= Particle.particleSize;
}
}
Help!
>Solution :
Try this:
public class Particle : MonoBehaviour
{
public static Particle instance;
public float particleSize;
public Transform particle;
void Awake()
{
instance = this;
}
void Start()
{
particle.localScale *= particleSize;
}
}
public class Magnetic : MonoBehaviour
{
public Transform magnetic;
void Start()
{
magnetic.localscale *= Particle.instance.particleSize;
}
}