why doesn't the purple drone(enemy) shoot?
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);
}
}
}
Answer by thomaswkhutton · Apr 12, 2020 at 06:59 AM
Can you past the full code for your simpleEnemy.cs code please?
Your answer
![](https://koobas.hobune.stream/wayback/20220612231025im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
"The associated script cannot be loaded" 0 Answers
[Question] Unity C# Set a Player Class and refence issue 0 Answers
How to assign GameObject to Script? 1 Answer
How does the rigged finger script work 0 Answers
How can I call a function once in Update according to a flag bool variable state false/true ? 3 Answers