The math is not mathing, literally. How do I get these inputfields to cooperate?
So I'm trying to get some math to output automatically in one input field when a number is inputted into another input field. But for some reason it's not connecting. I tried running two debugs in my code and those aren't showing up. I'm getting no errors so I don't know what to do at this point. What do you guys think?
The code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class MathScript : MonoBehaviour
{
public TMP_InputField inputY;
public TMP_InputField inputX;
public void CalculateX()
{
Debug.Log("CalculateX called");
if (string.IsNullOrEmpty(inputY.text)) {
return;
}
float y = float.Parse(inputY.text);
float x = (y - 10) / 2;
inputX.text = x.ToString();
Debug.Log("Calculated x value: " + x);
}
}
And screenshots:
https://imgur.com/a/vjhGglg
I've been using chatGPT to help learn the code and debug but there's only so much it can do since it's training data is a couple years old at this point.
So what do you guys think?
Posted Apr 1, 2023, 7:01 PM UTC
19