I'm trying to get an instance of another script of mine to call one of it's methods but whatever I try I get this error:
NullReferenceException: Object reference not set to an instance of an object
ZombieBulletHitManager.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/ZombieBulletHitManager.cs:22)
Here is my code for ZombieBulletManager:
using UnityEngine;
using System.Collections;
public class ZombieBulletHitManager : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other) {
if(other.gameObject.ToString().StartsWith("ZombieBullet")){
// Add the blood animation.
spawnBlood();
// Destroying the game objects
gameObject.GetComponent<ArcherBulletShootHandler>().removeBullet(other.gameObject);
Destroy (other);
Destroy(gameObject);
}
}
private void spawnBlood(){
GameObject go = Instantiate(
Resources.Load<GameObject>("ZombieBlood"),
transform.position,
Quaternion.identity) as GameObject;
}
}
EDIT: Apparently this is a duplicate however it's not, I have no idea where is null on the line gameObject.GetComponent().removeBullet(other.gameObject);
Any help would be great, thank you!