How do insert a variable in the middle of a string?

void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
min = guess;
guess = (max + min) / 2;
Debug.Log("Higher? Is your number " + guess);
}

So, that returns “Higher? Is your number xxx”

What if I want is to say “Higher? Is xxx your number?” or “Higher? Is your number xxx?” with the question mark?

Simply put: how do you continue a string after a variable? Or does a variable always have to be at the end?

Hi @Michael_Rousseau,

Good question, It’s pretty simple.

You just need to continue with a ‘+’.

So in your case you would have something like:

Debug.Log("This is your first string " + variable + " this is your second string " + secondVariable);

and so on. Hope that helps.

Cheers,
Todd

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms