Hello. This is my first post on the forums so please be gentle with me.
I’ve just started learning game dev and am following this tutorial.
I am around the 3 hr 3 min mark, and I am getting the following error.
Assets\Scripts\FloatingTextManager.cs(20,37): error CS0029: Cannot implicitly convert type ‘FloatingTextManager’ to ‘FloatingText’
Assets\Scripts\FloatingTextManager.cs(45,16): error CS0029: Cannot implicitly convert type ‘FloatingText’ to ‘FloatingTextManager’
here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FloatingTextManager : MonoBehaviour
{
public GameObject textContatiner;
public GameObject textPrefab;
private List<FloatingText> floatingText = new List<FloatingText>();
private void Update()
{
foreach (FloatingText txt in floatingText)
txt.UpdateFloatingText();
}
public void Show(string msg, int fontSize, Color color, Vector3 position, Vector3 motion, float duration)
{
FloatingText floatingText = GetFloatingText();
floatingText.txt.text = msg;
floatingText.txt.fontSize = fontSize;
floatingText.txt.color = color;
floatingText.go.transform.position = Camera.main.WorldToScreenPoint(position); // Transfer world space to screen space so we can use it in the UI
floatingText.motion = motion;
floatingText.duration = duration;
floatingText.Show();
}
private FloatingTextManager GetFloatingText()
{
FloatingText txt = floatingText.Find(t => !t.active);
if(txt == null)
{
txt = new FloatingText();
txt.go = Instantiate(textPrefab);
txt.go.transform.SetParent(textContatiner.transform);
txt.txt = txt.go.GetComponent<Text>();
floatingText.Add(txt);
}
return txt;
}
}