The question is answered
when I click the image don't change
I want to make a clicker game but when i click the image don't change.
This it the code:
using UnityEngine; using System.Collections;
public class OnClick : MonoBehaviour {
public UnityEngine.UI.Text pcdisplay;
public int pc = 0;
public int pcperclick = 1;
void update()
{
pcdisplay.text = "PC: " + pc;
}
public void Clicked()
{
pc += pcperclick;
}
}
please help me
Try Update ins$$anonymous$$d of update. Function names are case-sensitive.
Answer by MakerDavid · May 14, 2016 at 11:10 PM
You have to convert pc to String.
public UnityEngine.UI.Text pcdisplay;
public int pc = 0;
public int pcperclick = 1;
string converted;
void update()
{
converted = pc.toString();
pcdisplay.text = "PC: " + converted;
}
public void Clicked()
{
pc += pcperclick;
}
I could be wrong though, and I just wrote that at the top of my head but it's worth a shot.
It's not neccessarily wrong, because there is no need to convert a number type to add it to a string. But it's way to complicated to do:
string newVar;
newVar = pc.toString();
TextObject.text = newVar;
Ins$$anonymous$$d of:
TextObject.text = pc.toString();
You've still got update
ins$$anonymous$$d of Update
Follow this Question
Related Questions
I need help with a click to destroy game 1 Answer
ScreenPointToRay 0 Answers
How can I change image when click Icon? 1 Answer
How to make an avatar pop up when clicking a button??/ 0 Answers