前提・実現したいこと
敵を倒したらスコアが入るようにしたくて、以下のスクリプトを作ったんですが、敵をPrefabで作るようにしたところ、以下のエラーメッセージが出て、NewTextのままになってしまいます。■■な機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object
point.Update () (at Assets/シューティング素材/point.cs:22)
### 該当のソースコード using System.Collections; using System.Collections.Generic; using UnityEngine; public class enemy : MonoBehaviour { public int eHp = 10; // Use this for initialization void Start () { } // Update is called once per frame void Update() { if (transform.position.y >= 5) { transform.Translate(0, -0.1f, 0); } float a = Random.Range(0, 0.1f); float b = Random.Range(-0.3f,-0.1f); if (transform.position.y < 5) { transform.Translate(0.1f, -0.1f, 0); transform.Translate(0, -0.1f, 0); } if (this.eHp == 0) { Destroy(gameObject); } } void OnTriggerEnter2D(Collider2D other) { this.eHp -= 5; } } using System.Collections; using System.Collections.Generic; using UnityEngine; public class enemyresporn : MonoBehaviour { public GameObject enemyprefab; float span = 2.0f; float delta = 0; // Use this for initialization void Start () { } // Update is called once per frame void Update () { this.delta += Time.deltaTime; if (this.span < this.delta) { this.delta = 0; GameObject enemy = Instantiate(enemyprefab) as GameObject; int px = Random.Range(-10, 5); int py = Random.Range(6,7); enemy.transform.position = new Vector3(px, py, 0); } } } using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class point : MonoBehaviour { GameObject enemy; enemy script; GameObject point1; float p = 000000; float pp = 0; // Use this for initialization void Start () { this.enemy = GameObject.Find( "enemyPrefab(Clone)"); script = enemy.GetComponent<enemy>(); this.point1 = GameObject.Find("Score"); } // Update is called once per frame void Update () { int hp = script.eHp; if (hp == 0) { this.pp = +100; } this.point1.GetComponent<Text>().text = "" + p + pp; } } ```ここに言語名を入力 ソースコード ```C# ### 補足情報(FW/ツールのバージョンなど) Unity 2018.2.2.f1