实例代码如下:
using System.Collections;
using System.Collections.Generic;
using HedgehogTeam.EasyTouch;
using UnityEngine;
public class ScaleLimit : MonoBehaviour
{
Vector3 length;
//QuickPinch quickPinch;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//获取物体的大小
length = GetComponent<MeshFilter>().mesh.bounds.size;
//quickPinch = GetComponent<QuickPinch>();
}
void ScaleLimit2() {
float xlength = length.x * transform.lossyScale.x;
float ylength = length.y * transform.lossyScale.y;
float zlength = length.z * transform.lossyScale.z;
//Vector3 aa = transform.localScale;
if (xlength >= 2) {
transform.localScale = new Vector3(2, 2, 2);
//quickPinch.enabled = false;
}
if (xlength <= 0.5)
{
transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
//quickPinch.enabled = false;
}
}
}