I got an error, I did GetComponent () but the script was called ShipControll, I changed the name of the ShipControll script to ShipController and I got an error, I still didn’t understand why it appeared because I changed both the external name and the internal name in In the script, I decided to change the mentions in the ShipController script to ShipControll and the purple drone (enemy) stopped firing the bullet prefab and a NullReferenceException error occurred: Object reference not set to an instance of an object
simpleEnemy.Start () (at Assets / scripts / enemy / simpleEnemy.cs: 15) help fix this please
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class simpleEnemy : MonoBehaviour
{
public int Life_points;
public GameObject bullet;
public float shootDelay;
public Transform shootPoint;
public ShipControll Ship;
void Start()
{
Ship = GameObject.Find("ShipPlayer").GetComponent<ShipControll>();
InvokeRepeating("Shoot",2,shootDelay);
}
void Shoot()
{
GameObject b = Instantiate(bullet, shootPoint.position, Quaternion.identity) as GameObject;
}
void Damage(int dmg)
{
Life_points -= dmg;
if(Life_points < 0)
{
Life_points = 0;
}
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.CompareTag("shipB"))
{
Damage(Ship.bulletDmg);
Destroy(coll.gameObject);
}
}
}