Last active
August 20, 2016 17:02
-
-
Save takoyakiroom/b30fa62719b70a6168c134bf62889345 to your computer and use it in GitHub Desktop.
たこルカRC
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; | |
public class Car : MonoBehaviour | |
{ | |
private float power = 0; | |
private float LR = 0; | |
private float direction = 0; | |
// Use this for initialization | |
void Start() | |
{ | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
// 速度がないと向きは変えられない | |
if (System.Math.Abs(power) > 0) | |
{ | |
// 向き | |
direction += LR * 3.0f; | |
transform.rotation = Quaternion.Euler(0, direction, 0); | |
} | |
// 速度 | |
transform.position -= transform.forward * power * 0.02f; | |
Debug.Log("LR:" + LR + " power:" + power); | |
} | |
// アクセル | |
public void Accel(float fPower) | |
{ | |
power = fPower; | |
Debug.Log("power:" + power); | |
} | |
// ハンドル | |
public void Handle(float fLR) | |
{ | |
LR = fLR; | |
Debug.Log("LR:" + LR); | |
} | |
} |
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; | |
public class Car_ctrl : MonoBehaviour | |
{ | |
//ボタンID | |
private Valve.VR.EVRButtonId triggerButton = Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger; | |
private Valve.VR.EVRButtonId gripButton = Valve.VR.EVRButtonId.k_EButton_Grip; | |
// コントローラ取得 | |
private SteamVR_Controller.Device ctrl { get { return SteamVR_Controller.Input((int)trackedObj.index); } } | |
private SteamVR_TrackedObject trackedObj; | |
private Car target; // 操作するオブジェクト | |
// Use this for initialization | |
void Start() | |
{ | |
// Takoruka取得 | |
trackedObj = GetComponent<SteamVR_TrackedObject>(); | |
var obj = GameObject.Find("Takoruka"); | |
target = obj.GetComponent<Car>(); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
if (ctrl == null) | |
{ | |
Debug.Log("コントローラない"); | |
return; | |
} | |
if (target == null) | |
{ | |
Debug.Log("たこルカいない"); | |
return; | |
} | |
// トリガボタンのチェック | |
float value = ctrl.GetAxis(triggerButton).x; | |
// 離している時、0にはならないことがあるので | |
if (value > 0.1f) | |
{ | |
// グリップボタンを押しているか | |
if (ctrl.GetPress(gripButton)) | |
{ | |
// バックは前進の30%のスピードに | |
value *= -0.3f; | |
} | |
} | |
else | |
{ | |
value = 0; | |
} | |
// ハンドルはパッドの左右 | |
Vector2 position = ctrl.GetAxis(); | |
if (System.Math.Abs(position.x) < 0.1f) | |
{ | |
position.x = 0; | |
} | |
// Carに渡す | |
target.Accel(-value); | |
target.Handle(position.x); | |
Debug.Log("アクセル:" + value + " ハンドル:" + position.x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment