I’m doing tests with generic list so dont care about “Pokemon scripts” and don’t bother me about copyright and etc, that just for testing purposes…
So, i want that when a pokemon spawns it add to list his name, id and game object, pokemon script:
void Start () {
GameController.instance.AddPokemonToList(GameController.instance.pokemons.Count + 1, this.gameObject.name, this.gameObject);
}
and then, on the GameController script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class Pokemon {
public int id;
public string name;
public GameObject go;
}
public class GameController : MonoBehaviour {
public List<Pokemon> pokemons;
public static GameController instance;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void AddPokemonToList(int _id, string _name, GameObject _go) {
Pokemon _pokemon = new Pokemon {
id = _id,
name = _name,
go = _go
};
instance.pokemons.Add (_pokemon);
}
}
The console gives me an error on the pokemon script, null reference exeption.
What’s the problem ?