I've been working on a C# script in unity governing 'units' and in short, the compiler is telling me the '(' is unexpected in my integer function - 20th line in the pasted code below - before 'int cost' and I just can't find the issue with my script anywhere. If I remove the whole function there are no errors and it compiles successfully so I'm 99% sure the issue lies in the function itself. Apologies for the indentation, new to StackOverflow and bad at adding code onto here!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Iska.CNC.Units
{
public class UnitHandler : MonoBehaviour
{
public static UnitHandler instance;
[SerializeField]
private BasicUnit Pitbull, RaiderBuggy;
private void Start()
{
instance = this;
}
public (int cost, int attack, int attackRange, int health, int tier) GetBasicUnitStats(string type)
{
BasicUnit unit;
switch (type)
{
case "Pitbull":
unit = Pitbull;
break;
case "RaiderBuggy":
unit = RaiderBuggy;
break;
default:
Debug.Log("Error - unit cannot be found or does not exist");
return (0, 0, 0 ,0 ,0);
}
return (unit.cost, unit.attack, unit.attackRange, unit.health, unit.tier);
}
public void SetBasicUnitStats(Transform type)
{
foreach (Transform child in type)
{
foreach (Transform unit in child)
{
string unitName = child.name.Substring (0, child.name.Length - 1).ToLower ();
var stats = GetBasicUnitStats (unitName);
Player.PlayerUnit pU;
if (type == Iska.CNC.Player.PlayerManager.instance.playerUnits)
{
pU = unit.GetComponent<Player.PlayerUnit> ();
//set unit stats in each unit
pU.cost = stats.cost;
pU.attack = stats.attack;
pU.attackRange = stats.attackRange;
pU.health = stats.health;
pU.tier = stats.tier;
}
else if (type == Iska.CNC.Player.PlayerManager.instance.enemyUnits)
{
//set enemy stats
}
//if we have any upgrades or buffs, add them now
//add upgrades to unit stats
}
}
}
}
}