#Okay so now i got this but it still
1 messages · Page 1 of 1 (latest)
good idea
public string mathQuestion;
public TMP_Text TMP;
// Start is called before the first frame update
void Start()
{
// Generate random operands
int operand1 = Random.Range(1, 10);
int operand2 = Random.Range(1, 10);
// Generate a random operator (+ or -)
string[] operators = new string[] { "+", "-" };
string randomOperator = operators[Random.Range(0, operators.Length)];
// Construct the math question
mathQuestion = $"{operand1} {randomOperator} {operand2} = ?";
GetComponent<TMP_Text>().text = mathQuestion;
}```
Any errors in the console?
Where is the decleration we just worked out?
Oh myu bad.
You are still trying to reference a GetComponent
You need to learn how to problem solve.
Google things, and actually read errors and try to understand what they are telling you.
Now the only thing i have to do is create 3 targets, with 2 wrong answers and 1 correct one, And if i shoot the correct one a door opens
Thanks for the feedback I appreciate that
So make a Target Script with a flag on it for valid, and OnCollision check that flag, if it's correct you can just set a flag on the door, and have a check in the update, for if that flag is true the door opens.
a flag?
ahhh
True false, if ithe target's value matches the correct number have it set the target's valid flag to true on start.
And do I have to make 3 individual scripts? or
Or you could have it check against the answer oncollision every time.
I would say minimum, a Sign script, target script, and door script.
The sign sets the answer, the target checks that answer when hit, does it match? If yes then set door to open.
Ah cool thanks!
np
Any ideas on how to generate and connect the answer options with the targets?
Or is that the same thing as with the sign
You will need to do that to display the numbers on them, but to set the numbers you have to solve that.
You can have it auto generate two ,and then set the third to the answer.
Or just mix two random with the valid one in an array, and sccramble it.
Then in a for loop set the TMP text value on each target with what is in the array
so for example generate two answers between 1 - 100 and then one with the correct answer?
Yes, you will need to obtain the answer, and you need to generate the answer by doing the actual formula.
I'm making multiple of these rooms, that should still work right?
Depends on how you separate the rooms.
If each room is it's own scene and walking through the door loads the next scene it would work.
Actually either way it should.
Just make sure each is it's own individual set of independent objects.
Are you trying to procedurally generate the rooms?
No I think I'll just make a room or 5 for now
I was thinking about it tho
But the answer should look something along the lines of cs answer = operand1 randomOperator operand2; right?
I am not familiar with how to convert the operator unless you write a function for it.