0

I'm working on an improvement of the "Space Shooter project" i have multiple tiers of playerships, enemyships and asteroids and instead of blowing up both objects on collision, i want the larger playerships to survive collisions with smaller objects. I've been trying to achieve this by adding a CollisionController script on all enemy objects with a public float called Damage, i then try to access it from my playercontroller but i'm getting a nullreference error. I assumed it was because the enemy object was destroyed before the playercontroller could access the script but i've made sure the object isn't destroyed at all and i still get the error.

Below are the neccesary snippets of code:

On the player:

  void OnTriggerEnter (Collider other)
         {
             if (other.tag == "Enemy") 
             {
                 CollisionController collisionController = other.gameObject.GetComponent<CollisionController>();
                 Damager (collisionController.Damage); 
 //I get the Nullreference error on the line above -^;
         } 

On the enemy:

 public class CollisionController : MonoBehaviour {

         public float Damage;

 }
Steven
  • 166,672
  • 24
  • 332
  • 435
Dane Gillis
  • 137
  • 1
  • 3
  • 14

0 Answers0