Question by
simonlvschal · Apr 11, 2016 at 01:46 PM ·
uicanvas
how do i update specific Canvas Ui text?
so i know that this
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class RollStatsButton : Attributes {
//Text TxtAgility;
//Text TxtIntellect;
//Text TxtStamina;
// Use this for initialization
public void UpdateStrength(){
Text TxtStrength;
TxtStrength = GetComponent<Text> ();
TxtStrength.text = "Strength : " + Strength.ToString ();
}
void Start () {
//TxtAgility = GetComponent<Text> ();
//TxtIntellect = GetComponent<Text> ();
//TxtStamina = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {
Strength = Random.Range (1, 10);
Agility = Random.Range (1, 10);
Intellect = Random.Range (1, 10);
Stamina = Random.Range (1, 10);
Debug.Log ("Strength : " + Strength);
Debug.Log ("Agility : " + Agility);
Debug.Log ("Intellect : " + Intellect);
Debug.Log ("Stamina : " + Stamina);
UpdateStrength();
//TxtStrength.text = "Strenght :" + Strength.ToString();
//TxtAgility.text = "Agility :" + Agility.ToString ();
//TxtStamina.text = "Stamina :" + Stamina.ToString ();
//TxtIntellect.text = "Intellect :" + Intellect.ToString ();
}
}
}
will update the text but what i need to know is how do i update each of the Text fields? alone? i have 4 text fields and i want them to be updated by each one?
Comment
Answer by simonlvschal · Apr 11, 2016 at 02:47 PM
Nvm found solution
Text TxtStrength;
TxtStrength = GameObject.Find ("Strength").GetComponent<Text> ();
TxtStrength.text = "Strength : " + Strength.ToString ();
Your answer
Follow this Question
Related Questions
Canvas Renderer event 0 Answers
Block Graphic Raycaster on UI child elements 0 Answers
Problem with Images during Method-Call 0 Answers
Render canvas inside Sorting Group 0 Answers
Button custom collider 0 Answers