Skip to main content

DoTween

DoTween is a tool for tweening values which is very helpful for animations. This package is installed by default in the Genies Dev Kit and ready to use.

tip

Read the official DoTween website for more information.

TypeScript Usage

Most (if not all) of the API from the DoTween's documentation is accessible with TypeScript.

Package

In order to use certain libraries from the DoTween API, you will need to import from the DG.Tweening package, like so:

import { Ease, LoopType, RotateMode, Tweener } from 'DG.Tweening';

Example

Here is an example script that will rotate an object given some parameters:

import { MonoBehaviour, GameObject, Vector3 } from "UnityEngine";
import { Ease, LoopType, RotateMode, Tweener } from 'DG.Tweening';

export default class MyScript extends MonoBehaviour {

@Header("Rotation Settings")
@SerializeField private rotatingObject: GameObject;
@SerializeField private rotationDuration: number = 2;
@SerializeField private rotationDelay: number = 0;
@SerializeField private rotationEase: Ease = Ease.Linear;

private rotationTweener: Tweener;

private Start() : void {
this.AnimateObjects();
}

private Update() : void {

}

private AnimateObjects() : void {
if (this.rotatingObject)
{
this.rotationTweener?.Kill();
this.rotationTweener = this.rotatingObject.transform.DORotate(
new Vector3(0, 360, 0), this.rotationDuration, RotateMode.FastBeyond360)
.SetDelay(this.rotationDelay)
.SetEase(this.rotationEase)
.SetLoops(-1, LoopType.Restart);
}
}
}

Dotween Example