使用Time.deltaTime;
は、変数の一時Vector3
にInput.gyro.userAcceleration
を保存し、新しいと後でにそれを比較し、その後、タイマーを行うには、この
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
public Text x, y, z;
void Start()
{
Input.gyro.enabled = true;
}
void Update()
{
x.text = Mathf.Abs(Input.gyro.userAcceleration.x).ToString();
y.text = Mathf.Abs(Input.gyro.userAcceleration.y).ToString();
z.text = Mathf.Abs(Input.gyro.userAcceleration.z).ToString();
}
}
のように見えます次のフレームのジャイロからの値。新しい値が>
であれば古いvector3
値は、は古い値を上書きします。タイマーが起動しているときは、古い値を最高値として使用できます。
void Start()
{
Input.gyro.enabled = true;
}
bool firstRun = true;
float counter = 0;
float calcTime = 1; //Find highest gyro value every 1 seconds
Vector3 oldGyroValue = Vector3.zero;
Vector3 highestGyroValue = Vector3.zero;
void Update()
{
gyroFrame();
}
void gyroFrame()
{
if (firstRun)
{
firstRun = false; //Set to false so that this if statement wont run again
oldGyroValue = Input.gyro.userAcceleration;
counter += Time.deltaTime; //Increment the timer to reach calcTime
return; //Exit if first run because there is no old value to compare with the new gyro value
}
//Check if we have not reached the calcTime seconds
if (counter <= calcTime)
{
Vector3 tempVector = Input.gyro.userAcceleration;
//Check if we have to Update X, Y, Z
if (tempVector.x > oldGyroValue.x)
{
oldGyroValue.x = tempVector.x;
}
if (tempVector.y > oldGyroValue.y)
{
oldGyroValue.y = tempVector.y;
}
if (tempVector.z > oldGyroValue.z)
{
oldGyroValue.z = tempVector.z;
}
counter += Time.deltaTime;
}
//We have reached the end of timer. Reset counter then get the highest value
else
{
counter = 0;
highestGyroValue = oldGyroValue;
Debug.Log("The Highest Values for X: " + highestGyroValue.x + " Y: " + highestGyroValue.y +
" Z: " + highestGyroValue.z);
}
}
あなたの質問は混乱しています....どの軸が3つ以上の軸を確認したいですか?あなたがしようとしていることの詳細を説明してください... – Programmer
いいえ各軸の最高値を取得したい –
x、y、zの最高値を取得します。あなたが本当に助けを必要とする場合は、あなたの質問を変更し、あなたは最高値と何をアーカイブしようとしていることにより、何を意味するか追加します。 X、YおよびZの – Programmer