Yeah so it says
NullReferenceException: Object reference not set to an instance of an object
CharacterSpawner+d__5.MoveNext () (at Assets/Code/CharacterSpawner.cs:36)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.MonoBehaviour:StartCoroutine(String)
CharacterSpawner:Start() (at Assets/Code/CharacterSpawner.cs:27)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CharacterSpawner : MonoBehaviour
{
public GameObject characterKnight;
public GameObject characterWizard;
public bool cameraTarget;
private InventoryUI inventory;
void Start()
{
if (CharacterSelection.knight == true)
{
StartCoroutine("Knight");
}
if (CharacterSelection.wizard == true)
{
StartCoroutine("Wizard");
}
if (CharacterSelection.knight == false && CharacterSelection.wizard == false)
{
StartCoroutine("Knight");
}
inventory = GameObject.FindGameObjectWithTag("Inventory").GetComponent<InventoryUI>();
}
IEnumerator Knight()
{
Instantiate(characterKnight, transform.position, characterKnight.transform.rotation);
cameraTarget = true;
inventory.character.SetBool("Knight1", true);
yield return new WaitForSeconds(4f);
Destroy(this.gameObject);
}
IEnumerator Wizard()
{
Instantiate(characterWizard, transform.position, characterWizard.transform.rotation);
inventory.character.SetBool("Wizard1", true);
cameraTarget = true;
yield return new WaitForSeconds(4f);
Destroy(this.gameObject);
}
}
Am I not able to animate in a Coroutine?