Hello everyone…!
I have a question that has been bugging me for a while now and I wanted to ask you guys if you could help me. I have hooked my Arduino Uno up with 3 push buttons. I have set the arduino to Serial.write(1); up to 3 when the push buttons are pressed.
using UnityEngine;
using System.Collections;
using System.IO.Ports;
using System;
public class SimpleController : MonoBehaviour {
private Transform myTransform;
private CharacterController myController;
public int speed;
public float gravity;
public float gravityMod;
public bool regularGravity = true;
public float cooldown = 0;
SerialPort sp = new SerialPort("COM3", 9600);
// Use this for initialization
void Start () {
myTransform = this.transform;
myController = (CharacterController)this.GetComponent("CharacterController");
sp.Open ();
sp.ReadTimeout = 1;
}
// Update is called once per frame
void Update () {
if (sp.IsOpen){
try{
print(sp.ReadByte());
}
catch(System.Exception){
throw;
}
}
if(sp.ReadByte == 1){
myController.Move(new Vector3(-1,0,0)*speed);
}
if(sp.ReadByte == 2){
myController.Move(new Vector3(1,0,0)*speed);
}
if(sp.ReadByte == 3 cooldown <= 0){
regularGravity = !regularGravity;
gravity = -gravity;
cooldown = 1;
}
cooldown -= Time.deltaTime;
if(regularGravity){
gravity -= Time.deltaTime * 20f;
if(gravity < -30)
gravity = -30;
}else{
gravity += Time.deltaTime * 20f;
if(gravity > 30)
gravity = 30;
}
myController.Move(myTransform.up*gravity*gravityMod);
/*
if(Input.GetAxisRaw("MyMove")){
}
*/
}
void OnCollisionStay(Collision myCol){
print("We collided with something!!!");
}
}
This is my code.
The compiler complains over the three if-statements, with the following message: “Assets/Standard Assets/Character Controllers/Sources/Scripts/SimpleController.cs(45,23): error CS0019: Operator ==' cannot be applied to operands of type method group’ and `int’”
What is the problem, and how do I get around it? ![]()
Thanks