Is there a way to send a broadcast to all gameobjects in a scene (without requesting all gameobjects with findObjectsOfType and send it to them individually)?
It would be good enough if there's a way to iterate through the root GameObjects in the scene, then I could just use Broadcast on these gameobjects.
Really simple solution is to make everything in your scene a child of a single GameObject (call it world if you like). Then from this 'world' GameObject you can broadcast to all children:
There isn't a way to do this directly. The best thing I can think of is to add a tag to all root objects. You could then get them all with FindGameObjectsWithTag and broadcast to each of them.
Just had this issue and figured out another solution.
Attach the gameobject with whatever you wanna access and use get component to access the script. then change a public bool or float to what you want and allow the code to use these bools or floats to change things in the code:
public class Example1 : MonoBehaviour
{
public GameObject Player;
void Update()
{
if (Input.GetKey(KeyCode.W))
Player.GetComponent<Example2>().GoForawrd = true;
{
}
public class Example2 : MonoBehaviour
{
public bool GoForward = false;
void Update()
{
if (GoForward)
transform.position.x += 0.5f;
}
}