'意外的符号' void'期待{=>或者在哪里' Unity2D塔防游戏

时间:2018-01-07 22:33:55

标签: c# unity3d unity5

我一直试图创建一个Unity2D塔防游戏,并且似乎有一个问题是'意外的符号' void'期待{=>或者在哪里'在' string [] LoadLevelText(int i)'之后(第71行)。我正在按照教程完成所有工作,但这一个错误似乎无法修复,因为它只会引发更多问题。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class LvlManagerScr : MonoBehaviour {


    public int fieldWidth, fieldHeight;

    public GameObject cellPref;
    public Transform cellParent;

    public Sprite[] tileSpr = new Sprite[2];

    public List<GameObject> wayPoints = new List<GameObject>();
    GameObject[,] allCells = new GameObject[10, 22];

    int currWayX, currWayY;
    GameObject firstCell;


    void Start () {
        CreateLevel();
        LoadWaypoints();
    }

    void CreateLevel()
    {
        Vector3 worldVec = Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, 0));

        for (int i = 0; i < fieldHeight; i++)
            for(int k = 0; k < fieldWidth; k++)
            {
                int sprIndex = int.Parse(LoadLevelText(1)[i].ToCharArray()[k].ToString());
                Sprite spr = tileSpr[sprIndex];

                bool isGround = spr == tileSpr[1] ? true : false;

                CreateCell(isGround, spr, k, i, worldVec);
            }
    }

    void CreateCell(bool isGround, Sprite spr, int x, int y, Vector3 wV)
    {
        GameObject tmpCell = Instantiate(cellPref);
        tmpCell.transform.SetParent(cellParent, false);

        tmpCell.GetComponent<SpriteRenderer>().sprite = spr;

        float sprSizeX = tmpCell.GetComponent<SpriteRenderer>().bounds.size.x;
        float sprSizeY = tmpCell.GetComponent<SpriteRenderer>().bounds.size.y;

        tmpCell.transform.position = new Vector3 (wV.x + (sprSizeX * x), wV.y + (sprSizeY * -y));

        if (isGround)

        {
            tmpCell.GetComponent<CellScr>().isGround = true;

            if (firstCell == null)
            {
                firstCell = tmpCell;
                currWayX = x;
                currWayY = y;
            }
        }

        allCells[y, x] = tmpCell;

    }


    string[] LoadLevelText (int i)

    void LoadWaypoints()
    {
        GameObject currWay60;
        wayPoints.Add(firstCell);

        while (true) 
        {
            currWay60 = null;

            if (currwayX > 0 && allCells [currWayY, currWayX - 1].GetComponent<CellScr> ().isGround &&
               !wayPoints.Exists (x => x == allCells [currWayY, currWayX - 1])) 
            {
                currWay60 = allCells [currWayY, currWayX - 1];
                currWayX--;
                Debug.Log ("Next Cell is Left");
            } 
            else if (currwayX < 0 (fieldWidth - 1) && allCells [currWayY, currWayX + 1].GetComponent<CellScr> ().isGround &&
                    !wayPoints.Exists (x => x == allCells [currWayY, currWayX - 1])) 
            {
                currWay60 = allCells [currWayY, currWayX + 1];
                currWayX++;
                Debug.Log ("Next Cell is Right");
            } 
            else if (currWayY > 0 && allCells [currwayY - 1, currWayX].GetComponent<CellScr> ().isGround &&
                     !wayPoints.Exists (x => x == allCells [currWayY - 1, currWayX])) 
            {
                currWay60 = allCells [currWayY - 1, currWayX];
                currWayY--;
                Debug.Log ("Next Cell is Up");
            } 
            else if (currWayY < 0 (fieldHeight - 1) && allCells [currwayY + 1, currWayX].GetComponent<CellScr> ().isGround &&
                     !wayPoints.Exists (x => x == allCells [currWayY - 1, currWayX])) 
            {
                currWay60 = allCells [currWayY + 1, currWayX];
                currWayY++;
                Debug.Log ("Next Cell is Down");
            } 
            else
                break;

            wayPoints.Add (currWay60);

        }

    }               
}

在教程中似乎有一个带有省略号的框:

Screenshot

1 个答案:

答案 0 :(得分:0)

该行

string[] LoadLevelText (int i)

看起来不完整!

尝试用以下内容替换它以查看它现在是否有效:

string[] LoadLevelText(int i)
{
   return null;
}

您可能需要弄清楚LoadLevelText()应该做什么才能完成您的代码。