###前提・実現したいこと
UnityでParticleSystemをコード上で動かす簡単なスクリプトを作っています。
PlayerのスクリプトでSwitch文を使ってPlayerを動かすコードを書き、int playerStatus=1になったらParticleが再生される。
###発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object PlayerParticle.Update () (at Assets/PlayerParticle.cs:17)
###該当のソースコード
C#
1public class PlayerParticle : MonoBehaviour { 2 ParticleSystem particle; 3 public PlayerScript pc; 4 // Use this for initialization 5 void Start () { 6 particle = this.GetComponent<ParticleSystem>(); 7 particle.Stop (); 8 pc = GetComponent<PlayerScript> (); 9 } 10 11 // Update is called once per frame 12 void Update () { 13//ここでエラーがでる 14 if (pc.playerStatus==1) { 15 particle.Play (); 16 } 17 } 18}
###補足情報(言語/FW/ツール等のバージョンなど)

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/09 15:23
2018/01/10 01:09
2018/01/10 02:36