- Home /
Attaching GameObject and ParticleSystem to C# script
I've got a script that is not a component to anything, here is the code: using UnityEngine; using System.Collections;
public class PlayerCenter : MonoBehaviour {
public ParticleSystem particles;
public GameObject player;//these 2
void Start () {
particles.enableEmission = true;
}
public static void killPlayer(string reason){
GameObject.Destroy(player);
particles.transform.position = gameObject.transform.position;
particles.Play();
}
}
Apart from these errors :
I also want to find a way to attach my 'player' gameobject and 'particles' particle system to the script. Here is how my project looks like:
Thanks in advance!
Answer by $$anonymous$$ · Jul 31, 2014 at 04:34 PM
I think you should create at least Empty GameObject, attach your script to it, assign that variables in the Inspector and start looking for errors from there. Without doing this you cant get reference of PlayerCenter class because its deriving from MonoBehaviour and its not attached to any gameobject.
Your answer
Follow this Question
Related Questions
Static gameObject? 3 Answers
Distribute terrain in zones 3 Answers
GameObjects static array NullReferenceException 1 Answer
Particle system not destroying. 3 Answers
Multiple Cars not working 1 Answer