Unity控制物体有放缩弹一弹的效果

 

using UnityEngine;
using System.Collections;
//控制有放缩弹一弹的效果
public class ScaleController : MonoBehaviour {
    bool ismax = false;
    public float scaleSpeed = 0.003f;          //可调速度
    public float scalemax=2, scalemin=1.5f;    //可调范围
    void Update ()
 {
        Vector2 scale = transform.localScale;
        if (ismax==false)
        {
            scale.x += scaleSpeed;
            scale.y += scaleSpeed;
            transform.localScale = scale;
            if (scale.x>= scalemax)
            {
                ismax = true;
            }
        }
        else
        {
            scale.x -= scaleSpeed;
            scale.y -= scaleSpeed;
            transform.localScale = scale;
            if (scale.x <= scalemin)
            {
                ismax = false;
            }
        }    
    }
}

 

posted @ 2024-05-22 14:23  weigang  阅读(10)  评论(0编辑  收藏  举报