对UGUI的组件进行缩放
建个脚本放代码,调用Scale方法就行了
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIScale : MonoBehaviour {
public void Scale(GameObject go, float scaleTime, Vector2 pivot, Vector3 startScale, Vector3 targetScale)
{
if(null == go)
{
return;
}
RectTransform rectTransform = go.GetComponent<RectTransform>();
rectTransform.pivot = pivot;
float scaleSpeed = 7f / scaleTime;
go.transform.localScale = startScale;
StartCoroutine(Scale(go, scaleSpeed, targetScale));
StopCoroutine(Scale(go, scaleSpeed, targetScale));
}
private IEnumerator Scale(GameObject go, float scaleSpeed, Vector3 targetScale)
{
if (go != null)
{
while (go.transform.localScale != targetScale)
{
go.transfor