I am a beginner with no epxerience really so please make your explanations imsple and easy to understand :).
I would like a script to run on the click of a button, to grab the text input from a text field, store the input in a variable and then use it as the condition in an if statement.
Please also demonstarate how I would link up the script with the button or any other links I must establish.
Thanks - Any help would be much appreciated PS: I donât mind if your answer is in UnityScript or C#.
I bet this is horribly wrong but Iâd assume the code would look something like this.
var x = InputField.text;
if (var x = âHelloâ){
var score = score + 1;
}
I donât know, this is clearly my web design Javascipt mode coming out of me even though it is way different for Unity.
@5vStudios hello, thank you very much for your help! It doesnât work though. There is an error. Apparently the name InputField does not exist in the current context?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CheckAnsL1 : MonoBehaviour
{
public InputField iField;
public string myName;
public string myText;
void MyFunction()
{
Debug.Log(iField.text);
myName = iField.text;
if (myName == "MattCarter")
{
Debug.Log("Correct! The word " + myText + " cityi is correct! Ok");
}
else
{
Debug.Log("Incorrect! The answer was " + myText + " Ok");
}
}
}
If the input field contains the correct word, I want it to add a point to a scoring system but I havenât been able to work out who to create a scoring system regardless of all the tutorials I have watched. I donât even know how to get the score to display in a text box either and yes I have watched the tutorials on Unity but my application is different as the scripts in the tutorial apply to scenes with completely different coding to mine and I just canât seem to get anything to work for me?
Hello, I added the script to an empty gameobject and linked it to the button. I donât know what to choose under the menu that you can see in this image?