Hey, so i have a tooltip thing that appears when you hover over a button but im trying to make it so it fades in and our instead of just being there
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ToolTipSystem : MonoBehaviour
{
private static ToolTipSystem current;
public ToolTip toolTip;
public Image r;
public void Awake()
{
current = this;
}
public static void Show(string header = "")
{
ToolTipSystem TTS = new ToolTipSystem();
current.toolTip.SetText(header);
current.toolTip.gameObject.SetActive(true);
TTS.Fade();
}
public static void Hide()
{
current.toolTip.gameObject.SetActive(false);
}
public void Fade()
{
LeanTween.value(gameObject, 0, 1, 1).setOnUpdate((float val) =>
{
Color c = r.color;
c.a = val;
r.color = c;
});
}
}
The Fade() function works on its own, i origianlly tired having the fade function within the static void show but i get the CS0120 error
Paste the entire error message. Nobody memorizes error codes, and the message contains more information than just the code (e.g. line numbers)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ToolTipSystem : MonoBehaviour
{
private static ToolTipSystem current;
public ToolTip toolTip;
public Image r;
public void Awake()
{
current = this;
}
public static void Show(string header = "")
{
ToolTipSystem TTS = new ToolTipSystem();
current.toolTip.SetText(header);
current.toolTip.gameObject.SetActive(true);
LeanTween.value(gameObject, 0, 1, 1).setOnUpdate((float val) =>
{
Color c = r.color;
c.a = val;
r.color = c;
});
TTS.Fade();
}
public static void Hide()
{
current.toolTip.gameObject.SetActive(false);
}
public void Fade()
{
LeanTween.value(gameObject, 0, 1, 1).setOnUpdate((float val) =>
{
Color c = r.color;
c.a = val;
r.color = c;
});
}
}
Assets/Hover Over Info Package/ToolTipSystem.cs(27,25): error CS0120: An object reference is required for the non-static field, method, or property ‘Component.gameObject’
The Show method is static, which means it isn’t running on any particular object. so when you say “gameObject”, it has nowhere to get that reference from. But you do have a static “current” reference, so you should be able to use current.gameObject in that place.