facebook twitter hatena line email

「Unity/Csharp/DoTween」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(色変更)
行71: 行71:
 
  image.DOColor(Color.brue, 5f).SetEase(Ease.Linear);
 
  image.DOColor(Color.brue, 5f).SetEase(Ease.Linear);
  
===星型に移動する
+
===星型に移動する===
 +
*2Dの場合は、PathMode.Sidescroller2Dを追加する。
 +
*SetLookAtは向くまでの秒数
 +
 
 
<pre>
 
<pre>
 
Vector3[] movepath = new Vector3[6];
 
Vector3[] movepath = new Vector3[6];
行81: 行84:
 
movepath[5].Set(0f, 1f, 0f); // 1
 
movepath[5].Set(0f, 1f, 0f); // 1
 
// 星型頂点 https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q10137274530
 
// 星型頂点 https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q10137274530
 
+
GameObject.Find("Image").transform.DOPath(movepath, 5f, PathType.Linear, PathMode.Sidescroller2D)
 +
            .SetLookAt(0.01f)
 +
            .SetLoops(3, LoopType.Restart);
 
<pre>
 
<pre>
 +
ローカル値を使う場合は、DOLocalPathを使う

2021年8月3日 (火) 01:07時点における版

dotweenとは

アニメーションライブラリ

参考:https://qiita.com/broken55/items/df152c061da759ad1471

インストール

  1. unityassetsからdotweenを検索して、
  2. dotweenのfree ( https://assetstore.unity.com/packages/tools/animation/dotween-hotween-v2-27676 ) をダウンロード
  3. installし、
  4. importする
  5. OpenDoTweenUtilityPanelを開き
  6. SetupDotweenボタンを押して、Applyを押す。

サンプル

x=2、y=3のrootから見た座標に1秒後に移動する。

using DG.Tweening;
using UnityEngine;
public class SampleScene : MonoBehaviour
{
    void Start()
    {
        GameObject.Find("Image").transform.DOMove(new Vector3(2f, 3f, 0f), 1f);
    }
}

繰り返し

無限繰り返し

GameObject.Find("Image").transform.DOMove(new Vector3(2f, 3f, 0f), 1f);
.SetLoops(-1, LoopType.Restart);

2回指定

GameObject.Find("Image").transform.DOMove(new Vector3(2f, 3f, 0f), 1f);
.SetLoops(2, LoopType.Restart);

遅延動作

5秒待ってから動作

.SetDelay(5f);

Easeの動き

.SetEase(Ease.Linear); // 線形
.SetEase(Ease.OutSine); // 最初速く後ゆっくり
.SetEase(Ease.InExpo); // 最初ゆっくり後速く

https://github.com/Nightonke/WoWoViewPager/blob/master/Pictures/ease.png

動きを止める

オブジェクト指定

DOTween.Kill(this.transform);

tweenインスタンスを作って止める

Tween tween = GameObject.Find("Image").transform.DOMove(new Vector3(2f, 3f, 0f), 1f);
tween.Kill();

参考:https://qiita.com/broken55/items/df152c061da759ad1471

ローカル座標

DOLocalMoveとする

GameObject.Find("Image").transform.DOLocalMove(new Vector3(2f, 3f, 0f), 1f);

回転

5秒で、90度回転

.DORotate(Vector3.up * 90f, 5f)

色変更

5秒で青へ

Image image = GameObject.Find("Image").GetComponent<Image>();
image.DOColor(Color.brue, 5f).SetEase(Ease.Linear);

星型に移動する

  • 2Dの場合は、PathMode.Sidescroller2Dを追加する。
  • SetLookAtは向くまでの秒数
Vector3[] movepath = new Vector3[6];
movepath[0].Set(0f, 1f, 0f); // 1
movepath[1].Set(0.5878f, -0.8090f, 0f); // 5
movepath[2].Set(-0.9511f, 0.3090f, 0f); // 9
movepath[3].Set(0.9511f , 0.3090f, 0f); // 3
movepath[4].Set(-0.5878f, -0.8090f, 0f); // 7
movepath[5].Set(0f, 1f, 0f); // 1
// 星型頂点 https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q10137274530
GameObject.Find("Image").transform.DOPath(movepath, 5f, PathType.Linear, PathMode.Sidescroller2D)
            .SetLookAt(0.01f)
            .SetLoops(3, LoopType.Restart);
<pre>
ローカル値を使う場合は、DOLocalPathを使う