Hello Unity. I am a beginner C# coder. I wanted to access a public boolean for an object that is called HasTask. There are, in my case, 4 objects, and when i press a button, one is randomly “selected” and is given a task. I would like to show you what i have
//this is used by a raycast to instantiate a “GO HERE” indicator
Vector3 vec1 = new Vector3((float)x2, 0, (float)z2);
Instantiate(indicator, vec1 , Quaternion.identity);
//here i send the coordinates for where i want my object to go
SendObject(vec1);
}
}
}
void SendObject(Vector3 to){
//select random object from my pool of objects
System.Random rnd = new System.Random();
int i = rnd.Next(0, objectsTB.Length);
GameObject obj = (GameObject)objectsTB*;*
//here i want to put something like
obj.HasTask = true; / ← HasTask is a public varriable from the other script/
obj.TaskTo = to; /* same for this, TaskTo is a vector3 varraible that i want to pass*/
}
My issue that i cannot call the single script is because i have 4 objects using the same script, so i need to tell a specific script to “go here” and so forth. Please let me know if you need anything else