Help on scripting

I’m new to unity, today is my first time to use it I have make one game… it’s a board game from anime named phibrain… i only need a few things to do but i don’t know how :

  1. Make a legal move, now the square freely can move but i only want they to move horizontal and vertical, and give them a mark as legal move.
  2. Making a real player, as you see in the image there is 3 square each corner and i want make a cirlcle as a player for riding to the square legal move and the player can move from one square to other square that horizontally or vertically from them.
  3. I want make a winning message for the winner.
  4. I want make a turn for two player mode.
  5. I want make title/menu screen that contain “1 player, 2 player, Exit and Guide”.
  6. The last i want make AI.

I have edit the script to make a legal move but i have a problem, unity have parsing error with it, it i wil post the script here

using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {
	
	public int gameState = 0;			// In this state, the code is waiting for : 0 = Piece selection, 1 = Piece animation, 2 = Player2/AI movement
	//private int activePlayer = 0;		// 0 = Player1, 1 = Player2, 2 = AI, to be used later
	private GameObject SelectedPiece;	// Selected Piece
	
	//Update SlectedPiece with the GameObject inputted to this function
	public void SelectPiece(GameObject _PieceToSelect)
	{
		// Change color of the selected piece to make it apparent. Put it back to white when the piece is unselected
		if(SelectedPiece)
		{
			SelectedPiece.renderer.material.color = Color.white;
		}
		SelectedPiece = _PieceToSelect;
		SelectedPiece.renderer.material.color = Color.black;
	}
	
	// Move the SelectedPiece to the inputted coords
	public void MovePiece(Vector2 _coordToMove)
	{
		bool validMovementBool = false;
		Vector2 _coordPiece = new Vector2(SelectedPiece.transform.position.x, SelectedPiece.transform.position.z);

	{

	// Don't move if the user clicked on its own cube or if there is a piece on the cube
	if((_coordToMove.x != _coordPiece.x || _coordToMove.y != _coordPiece.y) || _boardPieces[(int)_coordToMove.x,(int)_coordToMove.y] != 0)
	{
		validMovementBool	= TestMovement (SelectedPiece, _coordToMove);
	}
	
	if(validMovementBool)
	{
		_boardPieces[(int)_coordToMove.x, (int)_coordToMove.y] = _boardPieces[(int)_coordPiece.x, (int)_coordPiece.y];
		_boardPieces[(int)_coordPiece.x , (int)_coordPiece.y ] = 0;
		
		SelectedPiece.transform.position = new Vector3(_coordToMove.x, _pieceHeight, _coordToMove.y);		// Move the piece
		SelectedPiece.renderer.material.color = Color.white;	// Change it's color back
		SelectedPiece = null;									// Unselect the Piece
		ChangeState (0);
		activePlayer = -activePlayer;
	}
}
		// Use the name of the _SelectedPiece GameObject to find the piece used
	switch (_SelectedPiece.name)
	{
	case "Pawn":
	// Pawn can move horizontally or vertically
	if((_deltaX != 0  _deltaY == 0) || (_deltaX == 0  _deltaY != 0)) 
	{
		_movementLegalBool = true;
	}
	break;
		default:
			_movementLegalBool = false;
			break;
		}
}

The problem is : Assets/Script/GameManager.cs(62,1): error CS8025: Parsing error

Your switch statement is outside of the class. Remove the “}” on line 47 and move it to line 63. This should be in the scripting section.

it won’t parsing… the problem at line 62… i don’t know what to do…

There is a scripting forum BTW :slight_smile:

Also, there is a an extra or wrong “{” on line 28. (and a whole bunch of variables that aren’t accounted for in the class.)

No need to move it.
As I can see he/she can simply remove the “}” on 47 and it’s fixed.

Cannot… the error not there…
Please help the full solution

Just remove the “{” on 28 (as well as moving the one on 47 to the end).

Every { should have a matching }, there should be open/close ones after defining a class, defining a method and when defining if/switch statements.

class MyClass : MonoBehavior
{
 // Class code in here


}

void SomeMethod()
{
 // method code in here
}

switch(someSwitch) 
{
 // switch code in here
}

// All combined:


class MyClass : MonoBehavior
{
 // Class code in here
    void SomeMethod()
    {
         // method code in here
        switch(someSwitch) 
        {
             // switch code in here
        }
    }
}

Your editor SHOULD automatically indent based on these, so they should line up correctly. If not, indent them yourself - you’ll soon see which ones belong and which ones don’t

This is the gossip forum. Post code help in scripting forum.

I would suggest you to take a few C# turtorials. Not only that the switch is outside of your class (and the tips above would fix that), but you’re nesting your methods wrong. Giving a solution in a thread would go beyond the scope of a posting, since there is a lot of mechanics you have to understand.

With that being said (and sorry i won’t give a proper solution), take some time to learn C#. There are some nice turtorials all over the web and even on Unitys’ side.