유니티와아두이노를활용한 -...
Transcript of 유니티와아두이노를활용한 -...
㈜헬로앱스 코딩교육김영준
공학박사, 목원대학교 겸임교수前 Microsoft 수석연구원
[email protected]://www.helloapps.co.kr
유니티와 아두이노를 활용한
VR 컨트롤러 개발
Part 04
유니티와 아두이노를 활용한 VR 컨트롤러 개발
외부 코드 편집기 실행하기
using System.Collections;using System.Collections.Generic;using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public GameObject MyCamera;
void Start () {
}
void Update () {
}}
유니티와 아두이노를 활용한 VR 컨트롤러 개발
코드 수정하기
using System.Collections;using System.Collections.Generic;using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public GameObject MyCamera;
void Start () {
}
void Update () {
float v = Input.GetAxis("Vertical") * Time.deltaTime * 10;float h = Input.GetAxis("Horizontal") * Time.deltaTime * 10;
MyCamera.transform.Translate(h, 0, v);}
}
유니티와 아두이노를 활용한 VR 컨트롤러 개발
코드 수정하기
using System.Collections;using System.Collections.Generic;using UnityEngine;
using System.IO.Ports;
유니티와 아두이노를 활용한 VR 컨트롤러 개발
코드 수정하기
public GameObject MyCamera;
SerialPort comm;
void Start () {
comm = new SerialPort("COM4", 115200);comm.Open();
}
유니티와 아두이노를 활용한 VR 컨트롤러 개발
코드 수정하기
void Update () {
string s = comm.ReadLine();
if ( !string.IsNullOrEmpty(s) )Debug.Log(s);
}
유니티와 아두이노를 활용한 VR 컨트롤러 개발
코드 수정하기
void Update () {
string s = comm.ReadLine();
if ( !string.IsNullOrEmpty(s) ){
if (s.StartsWith("<") && s.EndsWith(">")){
s = s.TrimStart('<').TrimEnd('>');string[] data = s.Split(',');
int d = int.Parse(data[0]);float x = float.Parse(data[1]);float y = float.Parse(data[2]);
x = x / 500.0f;y = y / 500.0f;
} }
}
유니티와 아두이노를 활용한 VR 컨트롤러 개발
코드 수정하기 void Update () {
string s = comm.ReadLine();
if (!string.IsNullOrEmpty(s)){
if (s.StartsWith("<") && s.EndsWith(">")){
s = s.TrimStart('<').TrimEnd('>');string[] data = s.Split(',');
int d = int.Parse(data[0]);float x = float.Parse(data[1]);float y = float.Parse(data[2]);
x = x / 500.0f;y = y / 500.0f;
float v = x * Time.deltaTime * 10;float h = y * Time.deltaTime * 10;
MyCamera.transform.Translate(h, 0, v);}
}}