Skip to content

Instantly share code, notes, and snippets.

@todorok1
Last active May 4, 2018 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/0656874b95293e54dd4cfa62b8bbd7be to your computer and use it in GitHub Desktop.
Save todorok1/0656874b95293e54dd4cfa62b8bbd7be to your computer and use it in GitHub Desktop.
Unityチュートリアル・コースアウト時の演出を実装するスクリプト
IEnumerator MissAnimation(float time){
// 落下時のアニメーション処理
RectTransform rt = fallTextObject.GetComponent<RectTransform>();
// ミステキストオブジェクトの初期位置と移動先位置
Vector3 initTextPos = rt.localPosition;
Vector3 targetPos = Vector3.zero;
// 引数で渡された秒数を足した時間(現在時刻に足す)
float finishTime = Time.time + time;
while (true){
// 処理完了の時刻に達したかの確認
float diff = finishTime - Time.time;
if (diff <= 0){
break;
}
// Lerpを計算するために時間進行度を計算
float rate = 1 - Mathf.Clamp01(diff / time);
// 初期位置から移動先位置までの直線上で、割合に応じた位置をセット
rt.localPosition = Vector3.Lerp(initTextPos, targetPos, rate);
// 1フレーム待機
yield return null;
}
// 移動先位置をセット
rt.localPosition = targetPos;
// ウェイト
yield return new WaitForSeconds(2.0f);
// ミステキストを元の位置に戻す
rt.localPosition = initTextPos;
// カメラコントローラで追随フラグをtrueにする
cameraController.SetTracingState(true);
// ボールを打った場所に戻して再開
StopFlying();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment