I have a prefab that is repeated many times to make many instances. It has a script on it with a variable. I can access the instances individually and I know how to call to a function in another script to change the variable in it.
My understanding is that by using the command (after the script is found and thisScript has it assigned to it):
thisScript.thisScriptFunction (variable);
I will end up triggering thisScriptFunction and changing the variable on every instance that has the script on it. If I want to only trigger the change on one instance of the many how do I specify in the command?
Your statement that calling the function on the found item effects all instances is not correct (unless I misunderstand you). This would only be true if the function you are calling is static to the type, or if the variable that function is modifying is static to the type.
If you have run your find method and have a reference to a single instance of an object, then calling methods on it (unless static) should only effect that single instance (unless as previously mentioned that function modifies static variables on the type).
It would be easier to get a clear idea of what your issue is / what you are trying if you could provide some code to refer to.
EDIT: Ok so I’ve written two monobehaviours that should demonstrate the idea of how to set a variable on an instance of a script individually.
public class OneOfMany : MonoBehaviour
{
private string message = "none";
public void SetMessage(string newMessage)
{
message = newMessage;
}
}
public class Test : MonoBehaviour
{
public void SetMessages ()
{
OneOfMany[] many = GameObject.FindObjectsOfType<OneOfMany>();
for(int i=0;i<many.Length;i++)
{
many*.SetMessage("I was number: "+i.ToString());*
}*
}* } You can apply the OneOfMany script to multiple objects in your scene, then if you add Test to one object and then ran the SetMessages method, it finds ALL of the OneOfMany scripts in the scene, and sets the message of each one which will then be unique.