Hi,
I’m new to Unity. For a school project we need to make a game that that you need to control with a LEGO EV3 Robot.
I’ve got the code to connect and use the EV3 as a controller. But the problem is that I’ve got a Parsing error that I don’t understand:
PlayerControl.cs(5,14): error CS8025: Parsing Error
Our teachers don’t work with Unity and nobody on school is able to help me since nobody used Unity. Therefore I’m here to ask you the more experienced/ pro’s for help.
EDIT:
Code cleanup after replys
using UnityEngine;
using System.Collections;
using EV3MessengerLib;
// EV3: Create an EV3Messenger object which you can use to talk to the EV3.
//EV3Messenger ev3Messenger = new EV3Messenger();
// EV3: Connect to the EV3 serial port over Bluetooth.
// If the program 'hangs' on a call to ev3Messenger.Connect,
// then your EV3 is not paired with your PC yet/anymore.
// To pair: Remove the EV3 from the Windows Bluetooth device list and add it again.
// Hardcoded serial port: put the serial port
// of the Bluetooth connection to your EV3 here!
public class PlayerControl : MonoBehaviour {
public GameControlScript control;
CharacterController controller;
bool isGrounded= false;
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
// EV3: The EV3Messenger is used to communicate with the Lego EV3
private EV3Messenger ev3Messenger;
//start
void Start () {
controller = GetComponent<CharacterController>();
ev3Messenger = new EV3Messenger();
ev3Messenger.Connect("COM03");
}
//// Game can be controlled by the connected EV3
//UpdateUsingEV3();
// Update is called once per frame
void Update (){
if (controller.isGrounded) {
animation.Play("run"); //play "run" animation if spacebar is not pressed
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0); //get keyboard input to move in the horizontal direction
moveDirection = transform.TransformDirection(moveDirection); //apply this direction to the character
moveDirection *= speed; //increase the speed of the movement by the factor "speed"
if (ev3Messenger.IsConnected)
{
// EV3: Receive a new command from mailbox "COMMAND" of the EV3
// and use it to change the direction of the paddle or to exit the game.
EV3Message message = ev3Messenger.ReadMessage();
if (message != null
&& message.MailboxTitle == "Command")
{
if (message.ValueAsText == "Right")
{
transform.position += transform.right * speed;
}
else if (message.ValueAsText == "Left")
{
transform.position += -transform.right * speed;
}
else if (message.ValueAsText == "Exit")
{
ev3Messenger.Disconnect();
//Exit();
}
}
}
//if (Input.GetButton ("Jump")) { //play "Jump" animation if character is grounded and spacebar is pressed
//animation.Stop("run");
//animation.Play("jump_pose");
//moveDirection.y = jumpSpeed; //add the jump height to the character
//}
if(controller.isGrounded) //set the flag isGrounded to true if character is grounded
isGrounded = true;
}
moveDirection.y -= gravity * Time.deltaTime; //Apply gravity
controller.Move(moveDirection * Time.deltaTime); //Move the controller
}
//check if the character collects the powerups or the snags
void OnTriggerEnter(Collider other)
{
if(other.gameObject.name == "Powerup(Clone)")
{
control.PowerupCollected();
//EV3 sends Message MakeNoise so it will play the sound Hit
ev3Messenger.SendMessage("MakeNoise", "Hit");
}
else if(other.gameObject.name == "Obstacle(Clone)" && isGrounded == true)
{
control.AlcoholCollected();
//EV3 sends Message MakeNoise so it will play the sound Crash
ev3Messenger.SendMessage("MakeMoreNoise", "Crash");
}
Destroy(other.gameObject);
}
}
}
I can explain things if the code if not clear enough.
Thank you in advance for looking into it!