0
using UnityEngine;
using System.Collections;

public class Weapon : MonoBehaviour {

public string Name;
public int RateOfFire;
int ROF;
public int Accuracy;
public int Ammo;
public Bullet Amunition;
public PCP shootingPoint;
[HideInInspector]
public bool IsActive = false;

void Start () 
{
    ROF = 0;
}

// Update is called once per frame
public void WeaponUpdate () 
{
    if(ROF != 0)
    {
        ROF --;
    }
}

public void Shoot()
{
    if(Ammo > 0 && ROF == 0)
    {
        shootingPoint.SendMessage("Create",Amunition);
        Ammo --;
        ROF = RateOfFire;
    }
}

}

"Note : PCP is shortcut to Prefab Shooting Point".

I got this error in the shooting method in the line "shootingPoint.SendMessage" I just dont understand why ? and I have the Components at the objects I placed in the shootingPoint and the Ammunation , so what is wrong ??

Here is an image to prove I attached objects : enter image description here

Steven
  • 166,672
  • 24
  • 332
  • 435
  • You need to initialize it I guess. – zs2020 Jun 19 '14 at 03:36
  • http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it?lq=1 – user2864740 Jun 19 '14 at 03:57
  • This is not pure .net Iam using unity engine which you have to deal with in a different way . – Mohamed Atef Jun 19 '14 at 03:59
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Jun 19 '14 at 04:11
  • I read the first part but most of the solutions were initializing it , which I cant do it in unity or if I can its not like normal c# coding ( Example example = new Example(); ) – Mohamed Atef Jun 19 '14 at 04:36

1 Answers1

0

Either shootingPoint or Amunition aren't objects yet. They're the only two things on that line that could be causing an issue.

Steve
  • 1,903
  • 5
  • 22
  • 30