Created
October 11, 2017 12:31
-
-
Save ljahier/2e7ca9d04b534285de5e26d43366f51c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.IO.Ports; | |
public class movePlayer : MonoBehaviour | |
{ | |
public float speed; | |
private float amoutToMove; | |
SerialPort sp = new SerialPort("COM3", 9600); | |
void Start() | |
{ | |
sp.Open(); | |
sp.ReadTimeout = 1; | |
} | |
void Update() | |
{ | |
amoutToMove = speed * Time.deltaTime; | |
if (sp.IsOpen) | |
{ | |
try | |
{ | |
MoveObject(sp.ReadByte()); | |
print(sp.ReadByte()); | |
} | |
catch (System.Exception) | |
{ | |
throw; | |
} | |
} | |
} | |
void MoveObject(int direction) | |
{ | |
if (direction == 1) | |
{ | |
transform.Translate(Vector3.left * amoutToMove, Space.World); | |
} | |
if (direction == 2) | |
{ | |
transform.Translate(Vector3.right * amoutToMove, Space.World); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment