Skip to content

Instantly share code, notes, and snippets.

@gok11
Created February 1, 2016 09:38
Show Gist options
  • Select an option

  • Save gok11/3d1181cd9935d7ed1e37 to your computer and use it in GitHub Desktop.

Select an option

Save gok11/3d1181cd9935d7ed1e37 to your computer and use it in GitHub Desktop.
AnimationCurveを使って値を変化させる ref: http://qiita.com/backlight1144/items/f3005bdc6324ba8b491b
using UnityEngine;
using System.Collections;
public class LinearMove : MonoBehaviour {
[SerializeField] private Vector3 destPos;
[SerializeField] private float tweenTime;
private bool isMoving = false;
// Use this for initialization
void Start () {
StartCoroutine(MoveCor());
}
IEnumerator MoveCor()
{
if (isMoving) yield break;
isMoving = true;
var startTime = Time.time;
var initPos = transform.position;
while (Time.time - startTime < tweenTime)
{
float rate = (Time.time - startTime) / tweenTime;
transform.position = Vector3.Lerp(initPos, destPos, rate);
yield return new WaitForEndOfFrame();
}
transform.position = destPos;
isMoving = false;
}
}
using UnityEngine;
using System.Collections;
public class TweenMove : MonoBehaviour {
[SerializeField] private Vector3 destPos;
[SerializeField] private float tweenTime;
[SerializeField] private AnimationCurve tweenCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
private bool isTweening = false;
// Use this for initialization
void Start () {
StartCoroutine(MoveCor());
}
IEnumerator MoveCor()
{
if (isTweening) yield break;
isTweening = true;
var startTime = Time.time;
var initPos = transform.position;
while (Time.time - startTime < tweenTime)
{
float rate = (Time.time - startTime) / tweenTime;
var curvedRate = tweenCurve.Evaluate(rate);
transform.position = Vector3.Lerp(initPos, destPos, curvedRate);
yield return new WaitForEndOfFrame();
}
transform.position = destPos;
isTweening = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment