Text issues

So I’m relatively new to C# and some text for a script I’m writing isn’t working? I’ve been trying to work it out for quite a bit and I can’t seem to work it out, any help would be appreciated. Here is my code

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Text : MonoBehaviour {
    Text gmpc;
    int gmpcs = 1;
    // Use this for initialization
    void Start () {
        
        gmpc=GetComponent<Text>();
        gmpc.text = gmpcs;

    }
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKeyDown('space'))
            gmpc.text = gmpcs + 1;
    }
}

I’m getting errors CS1061 and CS1012 and unexpected symbol

Thanks for the help :slight_smile:

Hello @username

In the above mentioned code you are trying to convert Type Int into Type Text(string) which is not possible without TypeCasting. Try using this code.

using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
public class TestingText : MonoBehaviour {
Text gmpc;
    int gmpcs = 1;
    // Use this for initialization
    void Start()
    {

        gmpc = GetComponent<Text>();
        gmpc.text = gmpcs.ToString();

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("space"))
            gmpc.text = (gmpcs + 1).ToString();
            Debug.Log(gmpc.text);
    }
}