NOT ASSIGNING VARIABLE
here is the code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class RMP_count : MonoBehaviour {
// REFORMED UI RMP DATA
public GameObject Rmp;
private Text text;
private string canvas_RMP_to_string;
private string y;
// Use this for initialization
void Start () {
text = Rmp.GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
float x = float.Parse(text.text);
y = text.text;
y = Math.Round((x / 1000) , 1).ToString();
text.text = y;
Debug.Log (text.text);
}
}
I get what i want in Debug.Log (text.text);
part and it is perfect but the problem is the part text.text = y;
it IS NOT ASSIGNING and in game scene it is not shows up !!! what can i do?
Answer by Er_ellison · Aug 02, 2017 at 01:55 PM
hey man ...
Thanx every one for helping
i just solved the problem from source code , i just found that variable from the source and then divided that to 1000 and problem been solved !
thanx every one ....
love u
Answer by NorthStar79 · Aug 02, 2017 at 11:41 AM
change this
text.text
with this
text.GetComponent<Text>().text
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class R$$anonymous$$P_count : $$anonymous$$onoBehaviour {
// REFOR$$anonymous$$ED UI R$$anonymous$$P DATA
public GameObject Rmp;
private Text text;
private string canvas_R$$anonymous$$P_to_string;
private string y;
// Use this for initialization
void Start () {
text = Rmp.GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
float x = float.Parse(text.text);
y = text.GetComponent<Text>().text;
y = $$anonymous$$ath.Round((x / 1000) , 1).ToString();
text.GetComponent<Text>().text = y;
Debug.Log (text.text);
}
}
void Update () {
float x = float.Parse(text.text);
y = $$anonymous$$ath.Round((x / 1000) , 1).ToString();
text.text = y;
Debug.Log (text.text);
}
Don't use GetComponent in update.
Answer by Bunny83 · Aug 02, 2017 at 01:19 PM
Are you sure that your "Rmp" reference actually point to the object in the scene? I suspect that this might reference a different instance, for example a prefab?
Change your Debug.Log to:
Debug.Log (text.text, Rmp);
Now when you click on the debug message in the console, the editor will highlight the referenced object yellow, either in the hierarchy or in the project view. Make sure that the object is the correct instance.
Variables play a significant role in computer program$$anonymous$$g for the reason that they allow programmers to write supple programs. ... A variable's data type shows what sort of worth the variable signifies, such as whether it is an integer, a floating-point quantity, assignment help, or a personality. The reverse of a variable is a endless.
Your answer
Follow this Question
Related Questions
Swapping a base and derived class giving unexpected results. 0 Answers
How to assign GameObject to script while in prefab mode? 0 Answers
Set public Image in canvas from script 0 Answers
How to make multiple sprites move using a loop from the scene script? 0 Answers
Variable not assigned but is. 0 Answers