Skip to content

Instantly share code, notes, and snippets.

@A-yonemura
Created July 4, 2018 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A-yonemura/06dc2804e903cb98a4d97bf06b17c35a to your computer and use it in GitHub Desktop.
Save A-yonemura/06dc2804e903cb98a4d97bf06b17c35a to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GoControll2 : MonoBehaviour {
[SerializeField] private Transform vr_Camera; // 自分の視点のカメラを設定する
// 前進速度
public float forwardSpeed = 7.0f;
// 後退速度
public float backwardSpeed = 2.0f;
private Vector3 velocity;
// Update is called once per frame
void Update () {
if(OVRInput.Get(OVRInput.Touch.PrimaryTouchpad)) {
// タッチパッドが指に触れている間
Move();
}
}
void Move() {
Vector2 pt = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad); ///タッチパッドの位置
velocity = vr_Camera.forward * pt.y; // vr_Camera視点での(0,0,1)
velocity.y = 0f; // カメラの高さは変えたくないのでyを0にする、x,zのみ変更する
if(pt.y > 0) // 前進
{
this.transform.position += velocity * forwardSpeed * Time.deltaTime;
}
else if(pt.y < 0) // 後退
{
this.transform.position += velocity * backwardSpeed * Time.deltaTime;
}
else
{
// タッチパッドのyが0の時は動かない
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment