#Okay so now i got this but it still

1 messages · Page 1 of 1 (latest)

tawny mauve
#

Let's get this all in a thread

#

Post your script code now.

bleak silo
#

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;

    }```
tawny mauve
#

Any errors in the console?

#

Where is the decleration we just worked out?

#

Oh myu bad.

#

You are still trying to reference a GetComponent

bleak silo
tawny mauve
#

You need to do TMP.text = mathQuestion;

#

Not a get component there

bleak silo
#

Omg dude

#

You got it

#

I have to start learning this is not okay haha

tawny mauve
#

You need to learn how to problem solve.

#

Google things, and actually read errors and try to understand what they are telling you.

bleak silo
#

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

bleak silo
tawny mauve
#

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.

bleak silo
#

a flag?

tawny mauve
#

You will have to reference the door on the target, and the correct answer.

#

Boolean

bleak silo
#

ahhh

tawny mauve
#

True false, if ithe target's value matches the correct number have it set the target's valid flag to true on start.

bleak silo
#

And do I have to make 3 individual scripts? or

tawny mauve
#

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.

bleak silo
#

Ah cool thanks!

tawny mauve
#

np

bleak silo
#

Any ideas on how to generate and connect the answer options with the targets?

#

Or is that the same thing as with the sign

tawny mauve
#

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

bleak silo
#

so for example generate two answers between 1 - 100 and then one with the correct answer?

tawny mauve
#

Yes, you will need to obtain the answer, and you need to generate the answer by doing the actual formula.

bleak silo
#

I'm making multiple of these rooms, that should still work right?

tawny mauve
#

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?

bleak silo
#

I was thinking about it tho

#

But the answer should look something along the lines of cs answer = operand1 randomOperator operand2; right?

tawny mauve
#

I am not familiar with how to convert the operator unless you write a function for it.