【发布时间】:2021-04-23 07:36:41
【问题描述】:
我一直在开发一个统一管理“单位”的 C# 脚本,简而言之,编译器告诉我“(”在我的整数函数中是意外的 - 下面粘贴代码的第 20 行 - 在 'int cost 之前' 而且我在任何地方都找不到我的脚本的问题。如果我删除整个函数,则没有错误并且它编译成功,所以我 99% 确定问题出在函数本身。为缩进道歉,新到 StackOverflow 并且不擅长在此处添加代码!
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
}
}
}
}
}
【问题讨论】:
-
感谢@Sinatr 解决了这个问题!
标签: c# unity3d compiler-errors