效果如下:
您只需要控制此对象进行激活,将对象设置为:gameObject.SetActive(true);即可实现此次效果
代码如下:
public class StartShowRun : MonoBehaviour
{Transform _localTransfrom;Vector3 _localScale;public AnimationCurve curve;//可编辑动画曲线[Range(0.1f, 6)]public float durationTime = 6;int _past = 0;float x, t;void Awake(){_localScale = this.transform.localScale;_localTransfrom = this.GetComponent<RectTransform>();this.transform.localScale = new Vector3(0.01f, 0.01f, 1);}//激活调用private void OnEnable(){_past = 0;t = 0;x = 0;}// Update is called once per framevoid Update(){if (_past == 0){t = x / durationTime;_localTransfrom.localScale = Vector3.Lerp(this.transform.localScale, _localScale, curve.Evaluate(t));x += Time.deltaTime;if (this.transform.localScale.x >= 0.998f){_past = -1;//开始缩小t = 0;x = 0;}}if (_past == -1){t = x / durationTime;_localTransfrom.localScale = Vector3.Lerp(this.transform.localScale, new Vector3(0.01f, 0.01f, 1), curve.Evaluate(t));x += Time.deltaTime;if (this.transform.localScale.y <= 0.1f){_past = 1;//代表结束transform.gameObject.SetActive(false);}}}
}