- Home /
Question by
mattio · May 22, 2012 at 01:21 PM ·
movementcharactercontrollercontroller
Is using an RFID as a Character controller possible?
I'm attempting to use an Arduino RFID to control a character (E.g. TAG 1 = forward, TAG 2 = backwards) So I have the RFID code to read the TAG's with Arduino and this C# code in Unity to take the TAG's from Arduinio:
using UnityEngine;
using System.Collections;
using System.IO.Ports;
public class ReadArdunio : MonoBehaviour {
public static string Data = " ";
SerialPort serial;
void Start () {
serial = new SerialPort("COM3", 2400);
serial.Open();
}
void Updated () {
Data = serial.ReadLine();
print(Data);
}
void Awake (){
InvokeRepeating ("Updated", 2, 1);
}
}
And I have this JavaScript to then write out that text in Unity as GUIText:
function Awake ()
{
InvokeRepeating ("UpdateJava", 2, 1);
}
function UpdateJava ()
{
var object = GameObject.Find("GUI Text");
var input = object.GetComponent(ReadArdunio).Data;
guiText.text = input;
}
I've attempted try to change this code into something that can control the character but am having no luck, as I've basically reached the limits of my abilities, this is what I have so far:
function Awake ()
{
InvokeRepeating ("UpdateJava", 2, 1);
}
function UpdateJava ()
{
var object = GameObject.Find("GUI Text");
var input = object.GetComponent(ReadArdunio).Data;
print (input); }
private var controller :CharacterController;
controller = gameObject.GetComponent(CharacterController);
private var moveDirection = Vector3.zero;
private var forward = Vector3.zero;
private var right = Vector3.zero;
if ( (" 0800E3CA33"))
{
guiText.text = "tag 1 found";
controller.transform.position.x = 1;
}
Can anyone help please! :)
Comment