ThePurpleArcher
ThePurpleArcher

Reputation: 67

Can't convert string to ui text in unity

I have looked around for solutions but nothing has worked so far, here is my code:

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

public class BirdController : MonoBehaviour 
{
    public float jumpVelocity;
    public Text jumpCooldownDisplayText = "";
    public float speed = 18;
    private Rigidbody rb;
    public float jumpCooldown = 0f;

    // Use this for initialization
    void Start ()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate ()
    {
        jumpCooldown -= Time.deltaTime;
        jumpCooldownDisplayText = Mathf.Round (jumpCooldown).ToString();

        if (Input.GetButtonDown ("Jump") && jumpCooldown <= 0) 
        {
            rb.velocity = Vector3.up * jumpVelocity;
            jumpCooldown = 0.5f;
        }

        float hAxis = Input.GetAxis("Horizontal");
        float vAxis = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(hAxis*speed, 0, vAxis*speed) * Time.deltaTime;

        rb.MovePosition(transform.position + movement);
    }
}

The error I'm getting is "Cannot implicitly convert type string' toUnityEngine.UI.Text'". I'm getting this error into different places of the code.

Upvotes: 1

Views: 8929

Answers (1)

ryeMoss
ryeMoss

Reputation: 4343

UI.Text is a UI text component, not the associated string. What you want is the text property of the UI Text:

jumpCooldownDisplayText.text = Mathf.Round (jumpCooldown).ToString();

Upvotes: 3

Related Questions