Hello, I am making a damage pool and I keep getting this error. I googled it for at least 25 min now and I am getting off track. I need to get back to work as soon as possible so here is the code. The error is pointing to the line where I call `Instantiate
Error:
InvalidCastException: Cannot cast from source type to destination type.
GameController+<spawnDamageTexts>c__Iterator1.MoveNext () (at Assets/Scripts/GameController.cs:52)
UnityEngine.MonoBehaviour:StartCoroutine(String)
GameController:initializeGame() (at Assets/Scripts/GameController.cs:27)
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameController : MonoBehaviour
{
[@HideInInspector]
public Queue<GUIText> damageTexts;
public GUIText damageText;
void initializeGame()
{
StartCoroutine("spawnDamageTexts");
}
IEnumerator spawnDamageTexts()
{
//Spawn damage texts over time
while(damgeTextsToSpawn > 0f)
{
GUIText clone = (GUIText)Instantiate(damageText, Vector3.zero, Quaternion.identity);
damageTexts.Enqueue(clone);
yield return new WaitForSeconds(1f);
}
}
}