LoginSignup
13
12

More than 5 years have passed since last update.

Unityのitweenをシンプルに実装。

Posted at

以下からダウンロード
https://code.google.com/p/itween/

iTween.csをpluginsにドラック&ドロップ
スクリーンショット 2014-08-21 10.34.20.png

以下のスクリプトを作成して対象のGameObjectにaddComponetする。

ItweenSample
using UnityEngine;
using System.Collections;

public class ItweenSample : MonoBehaviour {
    public GameObject gameobject;
    Hashtable table = new Hashtable();      // ハッシュテーブルを用意

    private void Start()
    {
        table.Add("x", 100);            // xを10まで移動
        table.Add("y", 50);         // yを5まで移動
        table.Add("time", 1.0f);        // トゥイーン時間は3秒
        table.Add("delay", 1.0f);       // 1秒遅らせてからトゥイーンスタート
        table.Add("oncomplete", "CompleteHandler");
        table.Add("oncompletetarget", gameObject);

        iTween.MoveTo(gameObject, table);   // 第二引数にハッシュテーブルをセット
        //iTween.MoveTo(gameObject, iTween.Hash("x", 20, "looptype", iTween.LoopType.loop));
        // 4秒かけて、y軸を260度回転
        //iTween.RotateTo(gameObject, iTween.Hash("y", 260, "time", 4.0f));
        // 4秒かけて、y軸を3倍に拡大
        //iTween.ScaleTo(gameObject, iTween.Hash("y", 3, "time", 4.0f));
    }

    private void OnTriggerStay(Collider other)
    {
        Debug.Log ("OnTriggerStay");
    }

    private void StartHandler()
    {
        Debug.Log ("StartHandler");
    }

    private void UpdateHandler()
    {
        Debug.Log ("UpdateHandler");
    }

    private void CompleteHandler()
    {
        Debug.Log ("CompleteHandler");
    }

}

(注意点)
MoveToをハッシュテーブルより後に書くと当然実行順番的にアウト。
EventHandlerに引数を入れられない。

13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12