Hi, I’m following the Roll-a-ball tutorial and have hit a snag, despite following the instructions carefully. When attempting to edit my code to display “You Win!” text, I run into this error:
“Assets/scripts/playerController.cs(21,19): error CS0029: Cannot implicitly convert type string' to UnityEngine.UI.Text’”
I assume it has something to do with line 49:
countText.text = "Count: " + count.ToString ();
–but this line didn’t cause problems when I was creating the count–only now that I’m adding the “You Win!” text.
Also, as far as I can tell, I’ve followed the instructions.
Thanks for any help!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class playerController : MonoBehaviour
{
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText = "";
}
void FixedUpdate()
{
float movehorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(movehorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 12)
{
winText.text = "You Win";
}
}
}