Skip to content

Instantly share code, notes, and snippets.

@GOROman
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GOROman/8843733 to your computer and use it in GitHub Desktop.
Save GOROman/8843733 to your computer and use it in GitHub Desktop.
Unity+OculusSDKでXboxコントローラの右アナログスティックの上下で高さを変えるサンプル
using UnityEngine;
using System.Collections;
public class JoyY : MonoBehaviour {
public float power = 0.02f;
public Vector3 targetPos;
// Use this for initialization
void Start () {
targetPos = transform.localPosition;
}
// Update is called once per frame
void Update () {
float h = OVRGamepadController.GPC_GetAxis(
(int)OVRGamepadController.Axis.RightYAxis
);
Vector3 v = new Vector3( 0, h * power, 0 );
targetPos += v;
// 必要ならクランプ
// targetPos.y = Mathf.Clamp( targetPos.y, -1.0f, 3.0f );
// まったり反映
transform.localPosition += ( targetPos - transform.localPosition ) * 0.1f;
}
}
@GOROman
Copy link
Author

GOROman commented Feb 6, 2014

これをアタッチしたオブジェクトの上・下の位置がXboxの右アナコンで変わります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment