Changing value of prefab without effecting all instances.

I have an AI prefab with a pathfinding script attached, I have another script attached that sets the AI’s target position on start. I set the pathfinding target to the AI’s target position using a public static variables however this obviously effects all of the instances of the prefab. How can I send a variable value from one script to another without it effecting all instances of the prefab?

If you have a static variable and you want to change it only for one instance, that is not possible.

You could make the target a public non-static variable so you can change it for only one instance. Once you have that, you can make a static method to change the variable for all the GameObjects with that component in the escene.

Note that this is EXTREMELY slow, so do this only if you don’t want to change the target very often.

public int target = 0;

public static void ChangeTarget(int value)
{
    GameObject[] allGameObjects = GameObject.FindObjectsOfType(typeof(YourComponentName)) as GameObject[];

    for (int i = 0; i < allGameObjects.Length; ++i)
    {
        allGameObjects*.GetComponent<YourComponentName>().target = value;*

}
}