I want to display the image using a tooltip. So when I point to the 3dobject, it will display the image that I already created. Right now I already set the sprite in the tooltip but I have an error in the function HideToolTip. In this function, I want to hide the image when the arrow/cursor is away from the object.
------TooltipManager Script-----
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class TooltipManager : MonoBehaviour
{
public static TooltipManager _instance;
public Image imageComponent;
//public SpriteRenderer imageComponent;
// SpriteRenderer spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(this.gameObject);
}
else
{
_instance = this;
}
}
// Start is called before the first frame update
void Start()
{
Cursor.visible = true;
gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
transform.position = Input.mousePosition;
}
public void SetAndShowToolTip(Sprite Image)
{
gameObject.SetActive(true);
imageComponent.sprite = Image;
}
public void HideToolTip()
{
gameObject.SetActive(false);
imageComponent.sprite = Sprite.Destroy();
}
}
Right now, I have an error in HideToolTip function.
------Tooltip Script-----
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Tooltip : MonoBehaviour
{
public Sprite Image;
private void OnMouseEnter()
{
TooltipManager._instance.SetAndShowToolTip(Image);
}
private void OnMouseExit()
{
TooltipManager._instance.HideToolTip();
}
}
imageComponent.sprite = Sprite.Destroy();
was a valid or useful thing to write? What do you intend that this line should accomplish? \$\endgroup\$