Test追加パックVol.2
This commit is contained in:
28
Assets/Scripts/InputLR.cs
Normal file
28
Assets/Scripts/InputLR.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
using Unity.VRTemplate;
|
||||
|
||||
public class InputLR : MonoBehaviour
|
||||
{
|
||||
void Update()
|
||||
{
|
||||
if(InputManagerLR.PrimaryButtonR())
|
||||
{
|
||||
OnPrimaryButtonR();
|
||||
}
|
||||
|
||||
if(InputManagerLR.PrimaryButtonR_OnPress())
|
||||
{
|
||||
OnPressPrimaryButtonR();
|
||||
}
|
||||
}
|
||||
|
||||
void OnPrimaryButtonR()
|
||||
{
|
||||
//邪魔になるためなし
|
||||
}
|
||||
|
||||
void OnPressPrimaryButtonR()
|
||||
{
|
||||
Debug.Log("押した瞬間");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/InputLR.cs.meta
Normal file
2
Assets/Scripts/InputLR.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae6f0d5ca1f0f42b6a38e38170777c16
|
||||
57
Assets/Scripts/InputManagerLR.cs
Normal file
57
Assets/Scripts/InputManagerLR.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class InputManagerLR : MonoBehaviour
|
||||
{
|
||||
static InputManagerLR instance;
|
||||
|
||||
[SerializeField]
|
||||
InputActionAsset ActionAsset;
|
||||
|
||||
InputActionMap ActionMap;
|
||||
InputAction m_PrimaryButtonR;
|
||||
InputAction m_SecondaryButtonR;
|
||||
InputAction m_PrimaryButtonL;
|
||||
InputAction m_SecondaryButtonL;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
GameObject.DontDestroyOnLoad(gameObject);
|
||||
ActionMap = ActionAsset.FindActionMap("Test");
|
||||
m_PrimaryButtonR = ActionMap.FindAction("XR_PrimaryButtonR", throwIfNotFound: true);
|
||||
m_PrimaryButtonL = ActionMap.FindAction("XR_PrimaryButtonL", throwIfNotFound: true);
|
||||
m_SecondaryButtonR = ActionMap.FindAction("XR_SecondaryButtonR", throwIfNotFound: true);
|
||||
m_SecondaryButtonL = ActionMap.FindAction("XR_SecondaryButtonL", throwIfNotFound: true);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ActionMap?.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ActionMap?.Disable();
|
||||
}
|
||||
|
||||
// Aボタン
|
||||
public static bool PrimaryButtonR() => instance.m_PrimaryButtonR.IsPressed();
|
||||
public static bool PrimaryButtonR_OnPress() => instance.m_PrimaryButtonR.WasPressedThisFrame();
|
||||
public static bool PrimaryButtonR_OnRelease() => instance.m_PrimaryButtonR.WasReleasedThisFrame();
|
||||
|
||||
// Xボタン
|
||||
public static bool PrimaryButtonL() => instance.m_PrimaryButtonL.IsPressed();
|
||||
public static bool PrimaryButtonL_OnPress() => instance.m_PrimaryButtonL.WasPressedThisFrame();
|
||||
public static bool PrimaryButtonL_OnRelease() => instance.m_PrimaryButtonL.WasReleasedThisFrame();
|
||||
|
||||
// Bボタン
|
||||
public static bool SecondaryButtonR() => instance.m_SecondaryButtonR.IsPressed();
|
||||
public static bool SecondaryButtonR_OnPress() => instance.m_SecondaryButtonR.WasPressedThisFrame();
|
||||
public static bool SecondaryButtonR_OnRelease() => instance.m_SecondaryButtonR.WasReleasedThisFrame();
|
||||
|
||||
// Yボタン
|
||||
public static bool SecondaryButtonL() => instance.m_SecondaryButtonL.IsPressed();
|
||||
public static bool SecondaryButtonL_OnPress() => instance.m_SecondaryButtonL.WasPressedThisFrame();
|
||||
public static bool SecondaryButtonL_OnRelease() => instance.m_SecondaryButtonL.WasReleasedThisFrame();
|
||||
}
|
||||
2
Assets/Scripts/InputManagerLR.cs.meta
Normal file
2
Assets/Scripts/InputManagerLR.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fc595679af414674be369cd3d5bc765
|
||||
62
Assets/Scripts/ItemCountDown.cs
Normal file
62
Assets/Scripts/ItemCountDown.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ItemCountDown : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject gameObjectRestore; //ゲームオブフェクトの復帰する座標を指定する
|
||||
|
||||
private bool isGrabbed = false;
|
||||
private bool isTouching = false;
|
||||
|
||||
public float grabItemTimeLimit = 5.0f; //ゲームオブジェクトの位置がリセットされるまでのタイマー
|
||||
private float timer; //スクリプト内のタイマーに用いる変数
|
||||
|
||||
void Start()
|
||||
{
|
||||
timer = 0.0f;
|
||||
}
|
||||
|
||||
public void GetGrab()
|
||||
{
|
||||
isGrabbed = true;
|
||||
isTouching = true;
|
||||
}
|
||||
|
||||
public void ExitGrab()
|
||||
{
|
||||
isTouching = false;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//制限時間が0秒の場合は、位置のリセットを実行しない
|
||||
if (grabItemTimeLimit != 0)
|
||||
{
|
||||
if (isGrabbed == true)
|
||||
{
|
||||
if (isTouching == false)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
|
||||
if (timer > grabItemTimeLimit)
|
||||
{
|
||||
//ゲームオブジェクトの速度をリセット
|
||||
var rigidbody = GetComponent<Rigidbody>();
|
||||
rigidbody.linearVelocity = Vector3.zero;
|
||||
//ゲームオブジェクトを指定位置に配置する
|
||||
rigidbody.transform.position = gameObjectRestore.transform.position;
|
||||
rigidbody.transform.rotation = gameObjectRestore.transform.rotation;
|
||||
//ゲームオブジェクトは不動の状態に戻る
|
||||
isGrabbed = false;
|
||||
timer = 0.0f;
|
||||
}
|
||||
}
|
||||
//プレイヤーが触っている場合はカウントダウンをリセット
|
||||
else
|
||||
{
|
||||
timer = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/ItemCountDown.cs.meta
Normal file
2
Assets/Scripts/ItemCountDown.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45dd4c486e2a64ef5a8f38d756b9dc2d
|
||||
Reference in New Issue
Block a user