Hi there! Still relatively new to Unity, so sorry if this is just some dumb rookie mistake. I have been following a youtube tutorial called "Damage Popup Text in Unity 5". However, I get stuck on using Resouces.Load to load a prefab. I have read all the common errors of not having a Resources folder etc. However, I still seem to be stuck and just can't load the Prefab. Any help and suggestions would be much appreciated!
I think the Prefab PopupDamagePArent is a GameObject and you are trying to load it as a c# script. Try: Code (CSharp): DamageText = Resources.Load<GameObject>("Prefabs/PopupDamageParent").GetComponent<DamageAnim>();
Thanks for the suggestion! But sadly, it still doesn't work. Debug.log(DamageText) still returns null and I still get the same error message. Any other potential solutions? Thanks!
That should work. The code's a bit strange, as it tries to load the same asset from the same location twice for no reason, but the path looks good. Unity 5 is a long time ago (2016), but the API you're working with hasn't changed. Could you show what the PopupDamageParent prefab looks like?
Haha yea the code is a bit weird. The if statement was some debugging I was doing and forgot to delete. Whoops! Attached is a pic of the prefab as well as it's child (in case it matters). Thanks!
Sorry for the late reply. If you still haven't solved the problem, the DamageAnim component is on the child, not the PopupDamageParent that we are loading. The script should be : Code (CSharp): DamageText = Resources.Load<GameObject>("Prefabs/PopupDamageParent").GetComponentInChildren<DamageAnim>();
A late reply is better than no reply! And no, I didn't solve the problem, just ignored it and worked on something else. Thank you so much for catching that! Solved my problem! Really appreciate it!