<景品表示法に基づく表記 > 本サイトのコンテンツには、商品プロモーションが含まれている場合があります。

DTMプラグイン販売サイト「Plugin Boutique」 セール情報

9月はMastering The Mixが熱い!
またiZotope MPSを中心にOzone11,Nectar4がセール
(Exclusive)がついているのはpluginboutique限定のセールで、他のWEBショップでは見かけない特化セール対象です!  ↓↓↓ 今すぐ【最新】のプラグインセールを見るにはこちら↓↓↓
Plugin Boutiqueのセール会場を今すぐ見るにはこちら

Unity

【Unity】iPhoneを振った時にゲームオブジェクトを動かす

スポンサードリンク

Iphone Shaking | Unity Communityより
iPhone自体を振ったとき、ゲームオブジェクトに対して何かの動作を加えるスクリプトが紹介されていました。

以下のスクリプトを作成して
アクションさせたいゲームオブジェクトにAdd componentします。
ソースはjavascriptです。

[code]

var accelerometerUpdateInterval : float = 1.0 / 60.0;
// The greater the value of LowPassKernelWidthInSeconds, the slower the filtered value will converge towards current input sample (and vice versa).
var lowPassKernelWidthInSeconds : float = 1.0;
// This next parameter is initialized to 2.0 per Apple's recommendation, or at least according to Brady! 😉
var shakeDetectionThreshold : float = 2.0;

private var lowPassFilterFactor : float = accelerometerUpdateInterval / lowPassKernelWidthInSeconds;
private var lowPassValue : Vector3 = Vector3.zero;
private var acceleration : Vector3;
private var deltaAcceleration : Vector3;

function Start()
{
shakeDetectionThreshold *= shakeDetectionThreshold;
lowPassValue = Input.acceleration;
}

function Update()
{
acceleration = Input.acceleration;
lowPassValue = Vector3.Lerp(lowPassValue, acceleration, lowPassFilterFactor);
deltaAcceleration = acceleration - lowPassValue;
if (deltaAcceleration.sqrMagnitude >= shakeDetectionThreshold)
{
// Perform your "shaking actions" here, with suitable guards in the if check above, if necessary to not, to not fire again if they're already being performed.

//iPhoneを振ったときにゲームオブジェクトへさせるアクション
Debug.Log("Shake event detected at time "+Time.time);
transform.Rotate(0,5, 0);
transform.localScale.x= 10.0f;

}
}
[/code]

Unityのことでわからなくなってつまづいたらネットで聞いてみよう!

質問をすると答えてくれるQ&Aサイト「teratail(テラテイル)」ではUnityの質問が5000件以上あり、
毎日様々な質問が投稿されています。

Q&Aサイトなんてたくさんあるじゃないかと言われてしまいそうですが、
teratailの良いところはエンジニアが抱える問題の解決を全力でサポートするところ。
つまりプログラミング、エンジニアリングに特化している点です。

WordPressフォーラムよりも早く返答がくることもありますので、
わからなくなったことを溜め込まずにサクッと解決してしまいましょう。
WordPressの情報収集にもおすすめです。

>>エンジニアのためのQ&Aサイト【teratail】の詳細はこちら[公式サイト]

安定した仕事量と給与がもらえるWEBエンジニアをめざしているなら

レバレジーズテックで転職サポート

Unityアセットストアの人気ツール

スポンサードリンク

-Unity
-