LoginSignup
29

More than 5 years have passed since last update.

【Unity】iTweenでハマったことメモ

Posted at

MoveBy関数には「islocal」パラメータがない

MoveByでislocalパラメータを追加してもエラーにならないため要注意!!!
ちなみにMoveToやMoveFromはありました。

アニメーションが終わったら呼ばれる関数(コールバック関数)にはターゲットが必要

たとえば、iTweenの移動処理が終わってゲームオブジェクトを削除したい場合は
oncompleteを保有しているゲームオブジェクトを明記したほうがいい

itween.cs
void OnTriggerStay(Collider other) {
    ins = Instantiate(PlusMoneyPrefab) as GameObject;

    Vector3 startPosition = new Vector3(startX, startY, -1);
    ins.transform.parent = Respawn.transform;
    ins.transform.localPosition = startPosition;
    ins.transform.localScale = new Vector3(50, 50, 0);

    Hashtable parameters = new Hashtable();
    parameters.Add("y", startY + 80);
    parameters.Add("islocal", true);
    parameters.Add("easeType", "easeInOutExpo");
    parameters.Add("time", 2);
    parameters.Add("oncomplete", "CompleteHandler");
    parameters.Add("oncompletetarget", gameObject);

    iTween.MoveTo(ins, parameters);
}

void CompleteHandler() {
    Destroy (ins);
}

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
29