0

I am fairly new to c# and am using a project as a tool to help me learn.

I've been trying to figure out where i'm going wrong with my code, but am struggling. I am trying to instantiate waves at different set spawn points, however I am coming up with the Null Reference Exception and cannot figure out where I am going wrong. All I know is that the issue lies with _sp, but don't know how I can fix it.

public class Wave {
    public string spawnName;
    public Transform spawnEnemy;
    public Transform spawnPoint;
    public int spawnCount;
    public float spawnRate;
}

static void SpawnEnemy (Transform _enemy) {
    Wave wave = new Wave();
    Transform _sp = wave.spawnPoint;
    Instantiate (_enemy, _sp.position, _sp.rotation);       
}

Any help would be appreciated

Damo
  • 67
  • 2
  • You created a new Wave, but didn't create a new spawnPoint object for that wave object. Also, even though you said _sp, always give the actual line that throws. – Dispersia Aug 23 '17 at 17:40
  • you aren't assigning any value to your object "wave". So it's properties are null - they have no values in them – Sean T Aug 23 '17 at 17:41
  • You need to create a constructor for Class Wave and as mentioned assign values.... – Kixoka Aug 23 '17 at 17:42

0 Answers0