Unity 自定义UGUI物体的位移动画

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum MoveType
{
     
    None,
    Loop,
    Pingpong
}

public class Itweem_move : MonoBehaviour {
     

    public MoveType _moveType;//循环模式

    [Header("起始点")]
    public Vector3 StartPosition;
    [Header("结束点")]
    public Vector3 EndPosition;
    [Header("速度")]
    public float MoveSpeed;
	// Use this for initialization
	void Start () {
     
        this.transform.localPosition = StartPosition;
	}
	
	// Update is called once per frame
	void Update () {
     
        if (_moveType == MoveType.None)
        {
     
            this.transform.localPosition = Vector3.MoveTowards(this.transform.localPosition, EndPosition, Time.deltaTime * MoveSpeed);
        }
        else if(_moveType == MoveType.Loop)
        {
     
            this.transform.localPosition = Vector3.MoveTowards(this.transform.localPosition, EndPosition, Time.deltaTime * MoveSpeed);
            if (Vector3.Distance(this.transform.localPosition, EndPosition) <= 0.1f)
            {
     
                this.transform.localPosition = StartPosition;
            }
        }
        else if (_moveType == MoveType.Pingpong)
        {
     
            this.transform.localPosition = Vector3.MoveTowards(this.transform.localPosition, EndPosition, Time.deltaTime * MoveSpeed);
            if (Vector3.Distance(this.transform.localPosition, EndPosition) <= 0.1f)
            {
     
                Vector3 _vec = StartPosition;
                StartPosition = EndPosition;
                EndPosition = _vec;
                this.transform.localPosition = StartPosition;
            }
        }
	}
}

你可能感兴趣的:(unity,游戏,unity3d,ugui,ui)