Hello. I am trying to get a text mesh I created to copy itself and locate itself above an object when the mouse scrolls over said object.
What I have so far actually works but at the same time I get an error during run-time that says, “Cannot cast from source type to destination type.”
As I said, this code works, it’s just that error that confuses me.
This is the code:
using UnityEngine;
using System.Collections;
public class WarriorSelection : MonoBehaviour {
public Transform target1;
public Object target2;
void OnMouseEnter() {
Vector3 ObjectPos = target1.transform.position;
GameObject NameClone = (GameObject)Instantiate(target2, ObjectPos, Quaternion.identity);
}
target1 is the object that I mouse over and target2 is the text mesh I display.
Also, I need help with destroying the text mesh during the function OnMouseExit() but whenever I try to use Destroy(NameClone), the compiler tells me that NameClone doesn’t exist in the current context.
Thanks for your help.