Multiple Spawn points, need a function to switch the main SP on click.

Hi,

So I have a War Factory that spawns tanks. If the user builds another War Factory I want to give the option to change the spawn location.

Having trouble figuring this one out.

I have on user click:

if(Input.GetKey(KeyCode.LeftAlt)  Input.GetMouseButton(0)){
					hit.collider.SendMessage("SetMainSpawnPoint",SendMessageOptions.DontRequireReceiver);
				}

which sets the main spawn point for that building to true, but if user builds another, and decides to set that one to the main spawn location, it will set that to true also, and there cant be 2 spawn pos.

Any ideas or ways I can about this?

Thanks.

You should have a list of the war factories already created, so that when you’ll set a new spawn point, you will set to all the others that they are no more the main spawn point. I think that this kind of code should be placed in a sort of GameManager and not in the WarFactory script itself.

Many ways to do it. For example,

Keep a list of all factories and iterate through them, setting all to false and then set the selected one to true.

Or have a player object keep a reference to its spawning factory and use that one when spawning a tank. Then you only need to change that reference.

Do take appropriate measures when the spawning factory gets destroyed.

if (warFactoryCount > 1) {
    if (settingNewSpawnLocation == true) {
        spawningGameobject.iAmMainSpawn = false;
    }
    if(Input.GetKey(KeyCode.LeftAlt)  Input.GetMouseButton(0)  spawningGameobject.iAmMainSpawn = false){
        hit.collider.SendMessage("SetMainSpawnPoint",SendMessageOptions.DontRequireReceiver);
}

You could try something like that idea