I’m making a Turn Based Strategy game, and each player has 3 “ship uses” meaning that they can move three units before it switches to the other player’s turn.
There are a few different unit types in this game so I gave each of them different “Move limits” to determine how far each unit can move if a player uses a ship use on it, by clicking it. (MoveLim in the code)
Each unit is a separate game object and therefore has its move limit kept track of individually as the script for tracking moveLim is attatched to each individual game object.
The turn system I created relies on the player turns switching after every few ship uses, so I was trying to make it so that when red player finishes with their turn, blue player’s moveLim on all its units is reset to 0.
Then, when blue player finishes THEIR turn, it would reset all of red player’s moveLim on all of the red units back to 0.
The issue is, although I can keep track of all the ship uses, I cannot find a way to reset the moveLims on multiple objects. I thought maybe foreach loops were the answer so I tried this…
void Update()
{
if (shipUse > 3)
{
if(redTurn)
{
redTurn =false;
shipUse = 0;
BlueTurn.SetActive (true);
RedTurn.SetActive (false);
Debug.Log("Red Turn Is Over");
GameObject.FindObjectsOfType(blueTeamMembership);
foreach(GameObject bluey in BlueTeamScript)
moveLim = 0;
}
else
{
redTurn = true;
shipUse = 0;
RedTurn.SetActive (true);
BlueTurn.SetActive (false);
GameObject.FindObjectsOfType(redTeamMembership);
foreach(GameObject redey in RedTeamScript)
moveLim = 0;
}
}
}
but to no avail…
Just this error:
Assets/Scripts/ShipUseCounter.cs(42,44): error CS1502: The best overloaded method match for `UnityEngine.Object.FindObjectsOfType(System.Type)’ has some invalid arguments
I also have a script that designated red team membership and blue team membership as true, attached to respective objects of each player. These are the bools I’m looking for.
Am I just misunderstanding foreach loops?
The RedTurn and BlueTurn set actives just make images in the scene appear that let the player know whose turn it is.
I’ve been racking my brain on this for quite some time. I’m not great at C# but I have no choice at this point.
Possibly Important Info:
A player clicks a unit and it becomes “selected” from there they use the arrow keys to move it from space to space, each movement from one space to another increases the moveLim of the specific unit, until it hits the cap of moveLim for that unit type.
The game is grid based, looks like this: