- Home /
Question by
BlazerLazer · Dec 10, 2017 at 04:13 AM ·
triggertriggersvalue
A value that is set to increase on trigger not working.
I'm having trouble with a script I have. Its supposed to increase a value when the player hits a trigger, and set the text to that value. Its like a Point system. The problem I get says something about not being able to convert float to string. Here is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PointSystem : MonoBehaviour {
[SerializeField] public Text myText;
public float Score = 0;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
myText.text = Score;
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
Comment
Best Answer
Answer by Play2D · Dec 10, 2017 at 09:43 AM
'Score' is a float and you're trying to put that value into 'myText.text' which is a string.
You need to do this:
myText.text = Score.ToString();