Skip to main content
Cleaned up post
Source Link

So I'm trying to access my enemy and spawning values from two different classes into a class that is trying to change them both. Although when I do this I keep getting a Null Reference Exception error saying the issue is. I have been looking for a few days now on solutions for this and have been unsuccessful so hopefully I will find it here. The error is where spawnManagerspawnManager first gets called.

This is the code that is trying to get the two values. (andAnd just to note I am trying to access these two values from my Welcome scene and these two values are in my Game scene but I do not know if this is affecting anything):

private EnemyAI enemy;
private SpawnManager spawnManager;

void Start() {
    spawnManager = GetComponent<SpawnManager>();
    enemy = GetComponent<EnemyAI>();
}

public void onEasy() {
    spawnManager.enemyShipWait = Random.Range(1f, 3f); <-- This line has the erroerror
    spawnManager.randomPowerupWait = Random.Range(7f, 12f);
    enemy.speed = 2.75f;
}

Thanks.

Edit: TheseThese are the two pictures of my scenes: Game Scene:   

Game Scene Welcome

Welcome Scene:   

Welcome Scene

So I'm trying to access my enemy and spawning values from two different classes into a class that is trying to change them both. Although when I do this I keep getting a Null Reference Exception error saying the issue is. I have been looking for a few days now on solutions for this and have been unsuccessful so hopefully I will find it here. The error is where spawnManager first gets called.

This is the code that is trying to get the two values. (and just to note I am trying to access these two values from my Welcome scene and these two values are in my Game scene but I do not know if this is affecting anything):

private EnemyAI enemy;
private SpawnManager spawnManager;

void Start() {
spawnManager = GetComponent<SpawnManager>();
enemy = GetComponent<EnemyAI>();
}

public void onEasy() {
spawnManager.enemyShipWait = Random.Range(1f, 3f); <-- This line has the erro
spawnManager.randomPowerupWait = Random.Range(7f, 12f);
enemy.speed = 2.75f;
}

Thanks.

Edit: These are the two pictures of my scenes: Game Scene:  Game Scene Welcome Scene:  Welcome Scene

I'm trying to access my enemy and spawning values from two different classes into a class that is trying to change them both. Although when I do this I keep getting a Null Reference Exception error. The error is where spawnManager first gets called.

This is the code that is trying to get the two values. (And just to note I am trying to access these two values from my Welcome scene and these two values are in my Game scene but I do not know if this is affecting anything):

private EnemyAI enemy;
private SpawnManager spawnManager;

void Start() {
    spawnManager = GetComponent<SpawnManager>();
    enemy = GetComponent<EnemyAI>();
}

public void onEasy() {
    spawnManager.enemyShipWait = Random.Range(1f, 3f); <-- This line has the error
    spawnManager.randomPowerupWait = Random.Range(7f, 12f);
    enemy.speed = 2.75f;
}

These are the two pictures of my scenes: Game Scene: 

Game Scene

Welcome Scene: 

Welcome Scene

added 141 characters in body
Source Link

So I'm trying to access my enemy and spawning values from two different classes into a class that is trying to change them both. Although when I do this I keep getting a Null Reference Exception error saying the issue is. I have been looking for a few days now on solutions for this and have been unsuccessful so hopefully I will find it here. The error is where spawnManager first gets called.

This is the code that is trying to get the two values. (and just to note I am trying to access these two values from my Welcome scene and these two values are in my Game scene but I do not know if this is affecting anything):

private EnemyAI enemy;
private SpawnManager spawnManager;

void Start() {
spawnManager = GetComponent<SpawnManager>();
enemy = GetComponent<EnemyAI>();
}

public void onEasy() {
spawnManager.enemyShipWait = Random.Range(1f, 3f); <-- This line has the erro
spawnManager.randomPowerupWait = Random.Range(7f, 12f);
enemy.speed = 2.75f;
}

Thanks.

Edit: These are the two pictures of my scenes: Game Scene: Game Scene Welcome Scene: Welcome Scene

So I'm trying to access my enemy and spawning values from two different classes into a class that is trying to change them both. Although when I do this I keep getting a Null Reference Exception error saying the issue is. I have been looking for a few days now on solutions for this and have been unsuccessful so hopefully I will find it here. The error is where spawnManager first gets called.

This is the code that is trying to get the two values. (and just to note I am trying to access these two values from my Welcome scene and these two values are in my Game scene but I do not know if this is affecting anything):

private EnemyAI enemy;
private SpawnManager spawnManager;

void Start() {
spawnManager = GetComponent<SpawnManager>();
enemy = GetComponent<EnemyAI>();
}

public void onEasy() {
spawnManager.enemyShipWait = Random.Range(1f, 3f); <-- This line has the erro
spawnManager.randomPowerupWait = Random.Range(7f, 12f);
enemy.speed = 2.75f;
}

Thanks.

So I'm trying to access my enemy and spawning values from two different classes into a class that is trying to change them both. Although when I do this I keep getting a Null Reference Exception error saying the issue is. I have been looking for a few days now on solutions for this and have been unsuccessful so hopefully I will find it here. The error is where spawnManager first gets called.

This is the code that is trying to get the two values. (and just to note I am trying to access these two values from my Welcome scene and these two values are in my Game scene but I do not know if this is affecting anything):

private EnemyAI enemy;
private SpawnManager spawnManager;

void Start() {
spawnManager = GetComponent<SpawnManager>();
enemy = GetComponent<EnemyAI>();
}

public void onEasy() {
spawnManager.enemyShipWait = Random.Range(1f, 3f); <-- This line has the erro
spawnManager.randomPowerupWait = Random.Range(7f, 12f);
enemy.speed = 2.75f;
}

Thanks.

Edit: These are the two pictures of my scenes: Game Scene: Game Scene Welcome Scene: Welcome Scene

Source Link

Null Reference Exception while getting Components

So I'm trying to access my enemy and spawning values from two different classes into a class that is trying to change them both. Although when I do this I keep getting a Null Reference Exception error saying the issue is. I have been looking for a few days now on solutions for this and have been unsuccessful so hopefully I will find it here. The error is where spawnManager first gets called.

This is the code that is trying to get the two values. (and just to note I am trying to access these two values from my Welcome scene and these two values are in my Game scene but I do not know if this is affecting anything):

private EnemyAI enemy;
private SpawnManager spawnManager;

void Start() {
spawnManager = GetComponent<SpawnManager>();
enemy = GetComponent<EnemyAI>();
}

public void onEasy() {
spawnManager.enemyShipWait = Random.Range(1f, 3f); <-- This line has the erro
spawnManager.randomPowerupWait = Random.Range(7f, 12f);
enemy.speed = 2.75f;
}

Thanks.