CS0019 error

Hi I am getting an error with code CS0019 in unity editor
It is Saying Operator ‘+’ can not be applied operands of type ‘string’ and ‘method group’

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using TMPro;

public class PlayerController : MonoBehaviour
{
    public float speed;
    public TextMeshProUGUI countText;

    private Rigidbody rb;
    private int count;
    private float movementX;
    private float movementY;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        count = 0;

        SetCountText();
    }

    private void OnMove(InputValue movementValue)
    {
        Vector2 movementVector = movementValue.Get<Vector2>();

        movementX = movementVector.x;
        movementY = movementVector.y;
    }
   
    void SetCountText()
    {
        countText.text = "Count: " + count.ToString;
    }

    private void FixedUpdate()
    {
        Vector3 movement = new Vector3(movementX, 0.0f, movementY);

        rb.AddForce(movement * speed);
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("PickUp"))
        {
            other.gameObject.SetActive(false);
            count = count + 1;

            SetCountText();
        }
    }
}

I assume it’s talking about

    void SetCountText()
    {
        countText.text = "Count: " + count.ToString;
    }

What you’re doing is passing the function “ToString” and not the value it returns when you run it, add “()” on the end.

Also pickup a basic programming book for your own sake and sanity before using a game engine like you are, gonna save you a lot of time in the long run.

2 Likes