- Home /
Variable not showing update in inspector
I have a script in an initialized prefab, called show, thats not changing value in the inspector, but when I do some Debug Logs, the logs show that it is updating in the script.
I have no other instances of the script anywhere else, so I know that is not a problem.
The script:
public class ShiTalkEffect : MonoBehaviour, IScreenEffect
{
[SerializeField]
private TextMeshProUGUI textTMP;
[SerializeField]
private string show;
public void Outcome(string myMove, string myStance, int myHP, int myStamina, string theirMove, string theirStance, int theirHP, int theirStamina)
{
show = "nothing";
Debug.Log("My move: " + myMove);
Debug.Log("Their move: " + theirMove);
if(theirMove.Contains("_hit"))
{
show = "Gotcha!";
Debug.Log("gotcha");
}
else
{
show = "whatever";
Debug.Log("whatever");
}
Debug.Log("Show: " + show);
textTMP.SetText(show);
}
}
Greetings, First of all, which variable/output from the code in your script are you hoping to view live in the inspector?
$$anonymous$$eep on Creating.
Well, I want "show" to change. On line 24, when show is printed to the Log, it shows that it has been changed, but in the inspector, it shows no change.
Hmmm, I have no clue... sorry, and hopefully someone can pick this up. It looks like it should behave as you desire...
No worries! I fixed it by removing the interface, and adding a lot more code. Its not as dynamic as I would like it to be, but I have it working now.
I have no idea why the interface call was not working, but removing fixed it. But now my code is gonna be a lil more messy :/
Answer by JoshuaTheJoker · Jul 26, 2019 at 09:49 AM
Update: Fixed it, had to remove the interface call, and making the code call the main script directly
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ShiTalkEffect : MonoBehaviour
{
[SerializeField]
private TextMeshProUGUI textTMP;
[SerializeField]
private string show;
[SerializeField]
private bool isSet;
[SerializeField]
private string myMove;
[SerializeField]
private string myStance;
[SerializeField]
private int myHP;
[SerializeField]
private int myStamina;
[SerializeField]
private string theirMove;
[SerializeField]
private string theirStance;
[SerializeField]
private int theirHP;
[SerializeField]
private int theirStamina;
void Start()
{
isSet = true;
show = "Lets go!";
}
void Update()
{
isSet = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.isSet;
if(!isSet)
{
myMove = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.myMove;
myStance = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.myStance;
myHP = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.myHP;
myStamina = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.myStamina;
theirMove = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.theirMove;
theirStance = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.theirStance;
theirHP = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.theirHP;
theirStamina = gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.theirStamina;
Debug.Log("My move: " + myMove);
Debug.Log("Their move: " + theirMove);
if(theirMove.Contains("_hit"))
{
show = "Gotcha!";
Debug.Log("gotcha");
}
else
{
show = "whatever";
Debug.Log("whatever");
}
gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent<Player>().screenEffect.isSet = true;
Debug.Log("Show: " + show);
}
textTMP.SetText(show);
}
}
Answer by game-dev333 · Jul 26, 2019 at 06:00 AM
I tried your code. Show is changing in inspector. here is code I used. check you are not getting any error
void Start()
{
StartCoroutine(trashItemsOnLevelEnd());
}
public IEnumerator trashItemsOnLevelEnd()
{
while (1==1)
{
Outcome("hi1", "hi1", 0, 0, "hi3", "hi4", 0, 0);
yield return new WaitForSeconds(1);
}
}
public void Outcome(string myMove, string myStance, int myHP, int myStamina, string theirMove,
string theirStance, int theirHP, int theirStamina)
{
show = "nothing";
Debug.Log("My move: " + myMove);
int randomno = Random.Range(0, 8);
theirMove = randomno % 2 == 0 ? "_hit" : "no";
Debug.Log("Their move: " + theirMove);
if (theirMove.Contains("_hit"))
{
show = "Gotcha!";
Debug.Log("gotcha");
}
else
{
show = "whatever";
Debug.Log("whatever");
}
Debug.Log("Show: " + show);
//textTMP.SetText(show);
}