I am trying to make a enemy attack my player and deal damage to player

I am trying to make a enemy attack my player but only deal 1damage per hit.
But everytime that the attack does hit my player it destroys him this is for a 2d side scroller game.

the main one i am having troblue with is the EnemyBullet.cs
// The Bullet Damage our Player
gameManager.SendMessage(“PlayerDamaged”, damageValue, SendMessageOptions.DontRequireReceiver);
gameManager.controller2d.SendMessage(“TakenDamage”, SendMessageOptions.DontRequireReceiver);

is what i keep getting
NullReferenceException: Object reference not set to an instance of an object
EnemyBullet.OnTriggerEnter (UnityEngine.Collider other) (at Assets/PYP Game/Script/EnemyBullet.cs:20)

My Enemy2D.cs

public class Enemy2D : MonoBehaviour {
//Reference to our GameManager Script
public GameManager gameManager;

// Enemies Starting/End Positions
float startingPos;
float endPos;

// Units Enemy Moves Right
public float unitsToMove = 5;
//Enemies Movement Speed
public int moveSpeed = 2;
// Enemy Moving Right or Left
bool moveRight = true;

// Enemies Health
int enemyHealth = 1;
// Types of Enemies
public bool basicEnemy;
public bool advancedEnemy;
public bool BossEnemy;


void Awake()
{
// On Load Gets Enemy Starting X
startingPos = transform.position.x;
// ON LOAD GETS OUR ENEMIES END POS BY ADDING THE UNITS TO THE STARTING POS
endPos = startingPos + unitsToMove;

if (basicEnemy) {
enemyHealth = 3;
}
if (advancedEnemy) {
enemyHealth = 6;
}
if (BossEnemy) {
enemyHealth = 25;
}
}

void Update()
{
if (moveRight){
rigidbody.position += Vector3.right * moveSpeed * Time.deltaTime;
}

if (rigidbody.position.x >= endPos){
moveRight = false;

}
if (!moveRight){
rigidbody.position -= Vector3.right * moveSpeed * Time.deltaTime;
}

if (rigidbody.position.x <= startingPos){
moveRight = true;
}
}

// Enemy Damage Value
public int damageVaule = 1;

void OnTriggerEnter(Collider col){
if (col.gameObject.tag == "Player") {
gameManager.SendMessage ("PlayerDamaged", damageVaule, SendMessageOptions.DontRequireReceiver);
gameManager.controller2d.SendMessage ("TakenDamage", SendMessageOptions.DontRequireReceiver);
}
}

// Emey Taking Damage
void EnemyDamaged(int damage){
if (enemyHealth > 0){
enemyHealth -= damage;
}

if (enemyHealth <= 0){
enemyHealth = 0;
Destroy (gameObject);
gameManager.curEXP += 10;
}
}

//Shows That we have takenDamage
float takenDamage = 0.2f;

public IEnumerator TakenDamage(){
renderer.enabled = false;
yield return new WaitForSeconds(takenDamage);
renderer.enabled = true ;
yield return new WaitForSeconds(takenDamage);
renderer.enabled = false;
yield return new WaitForSeconds(takenDamage);
renderer.enabled = true;
yield return new WaitForSeconds(takenDamage);
renderer.enabled = false;
yield return new WaitForSeconds(takenDamage);
renderer.enabled = true;
yield return new WaitForSeconds(takenDamage);
}
}

Shooting Script:

public class BossShooting : MonoBehaviour {
//Reference to our GameManager Script
public GameManager gameManager;

public int damageVaule = 1;

public Rigidbody bulletPrefab;
float coolDown;

public float xValue = -.75f;

// Update is called once per frame
void Update()
{
if (Time.time >= coolDown)
{
Fire();
}
}

void Fire()
{
// This INSTANTIATES BULLET FROM THE ENEMY POSITION
//Rigidbody bPrefb = Instantiate(bulletPrefab;transform.position,Quaternion.identity) as Rigidbody;

// INSTANTIATE FROM PLAYER + X POSITION
Rigidbody bPrefab = Instantiate(bulletPrefab, new Vector3(transform.position.x + xValue, transform.position.y, transform.position.z), Quaternion.identity) as Rigidbody;

bPrefab.rigidbody.AddForce (Vector3.left * 300);

coolDown = Time.time + Random.Range (3, 6);

}

}

my Bullet Script:

public class EnemyBullet : MonoBehaviour {

GameManager gameManager;

public int damageVaule = 1;

void OnBecameInvisible()
{
Destroy (gameObject);
}

void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log ("we Have Hit The Player");

// The Bullet Damage our Player
gameManager.SendMessage("PlayerDamaged", damageValue, SendMessageOptions.DontRequireReceiver);
gameManager.controller2d.SendMessage("TakenDamage", SendMessageOptions.DontRequireReceiver);

// Destroy our bullet
Destroy(gameObject);



}
}
void FixedUpdate(){
Destroy (gameObject, .5f);
}
}

please use code tags. Code it unreadable without them

Didn’t check the code since the error “NullReferenceException: Object reference not set to an instance of an object” is pretty self-explanatory (you are trying to use something that is null). The line of the error will indicate exactly what’s wrong.

Component orientation hint, make a script called HealthBehavior and use it for the player and all enemies. Make this behavior send a message to the owning object “OnDeath” every time a damage taken results in non-positive health. This will help keeping you sane as the number of damage sources and killable stuff keeps on increasing and increasing.

i already have a health area in my player script and enemy script I think its just not pulling from the collider col because i can walk into the enemy and take damage the same as before i tried to make it a projectile also

ok, seriously use code tags… go back and edit them in, and whilst you are at it, re-read the error message you’ve got. It says there is a problem in the “EnemyBullet.cs” script on line 23

my Bullet Script:
public class EnemyBullet : MonoBehaviour 
{
GameManager gameManager;
...
gameManager.SendMessage("PlayerDamaged", damageValue, SendMessageOptions.DontRequireReceiver); //line 23, only one object on this line "gameManager"... check it's existence in you code
gameManager.controller2d.SendMessage("TakenDamage", SendMessageOptions.DontRequireReceiver);
...
}

where are you setting the gameManager to be an instance of an object in the scene in that script?

the error is not on 23 its on 20

I want to say its not reading my gameManager witch is where i have PlayerDamage at