How to call a string inline as part of identifier of a new string?

This should be straight forward, but I can’t seem to find an answer. I’m trying to declare a string (String 2 below) to be located in another script by using a different string (String 1 below) from the active script.

Working within clickToDestroy.cs and pulling string 2 from RigidBodyFirstPersonController.cs

String 1: currentCount = (1,2,3,4,5,…~)
String 2: RigidbodyFirstPersonController.item(1,2,3,4,5,…~) (Depending on the value of currentCount, will be item1 item2 item3, etc.)

Is there a way to concatenate currentCount inline with RigidbodyFirstPersonController.item(insert currentCount here) during the declaration?

This is just a wild guess since I still don’t get the explenation but maybe you mean something like string.Format ?

string finalString = string.Format("{0} {1}", "Hello", "World!");

This will give you Hello World! as value for finalString.


so in your case

string String2 = string.Format("RigidbodyFirstPersonController.item{0}", currentCount);

(assuming currentCount is a string and not an int or something, otherwise you could use currentCount.ToString())