- Home /
Hi,can someone please help me? What is wrong with my cs code?Unity say Assets/Typer.cs(24,17): error CS0029: Cannot implicitly convert type `UnityEngine.UI.Text' to `UnityEngine.Texture'
using UnityEngine; using System.Collections; using UnityEngine.UI;
[RequireComponent(typeof(AudioSource))] [RequireComponent(typeof(Text))] public class Typer : MonoBehaviour {
public string msg= "Replace";
private Texture textComp;
public float startDelay = 2f;
public float typeDelay = 0.01f;
public AudioClip putt;
void Start()
{
StartCoroutine("TypeIn");
}
void Awake()
{
textComp = GetComponent<Text>();
}
public IEnumerator TypeIn()
{
yield return new WaitForSeconds(startDelay);
for(int i = 0; i < msg.Length; i++)
{
textComp.text = msg.Substring (0,i);
GetComponent<AudioSource>().PlayOneShot(putt);
yield return new WaitForSeconds(typeDelay);
}
}
public IEnumerator TypeOff()
{
for (int i = msg.Length; i >= 0; i--)
{
textComp.text = msg.Substring (0,i);
yield return new WaitForSeconds(typeDelay);
}
}
}
Answer by tanoshimi · May 26, 2016 at 06:40 PM
The answer is literally in the error message.
textComp is a Texture. You declare it as such in line 2:
private Texture textComp;
Yet, on line 15, you're trying to assign a Text component to it:
textComp = GetComponent<Text>();
You cannot implicitly convert type UnityEngine.UI.Text to UnityEngine.Texture.....
Yea,thanks,autowrite did that and i coud not find the error. Thanks alot again:)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Socket programming in unity 3 Answers
Multiple GUI.Labels to appear and disappear 1 Answer
C# GameObject Lists 2 Answers
Getting interactive grass texture or getting grass onto a plane instead of terrain. 2 Answers