using UnityEngine; public class ScaleControl : MonoBehaviour { bool flag; private Ray ray; private RaycastHit hit; public float speed = 5f; void Update() { //左击取消 ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity) && Input.GetMouseButtonDown(0)) { if (hit.transform.name == this.name) return; flag = false; } if (flag) { if (Input.GetKey(KeyCode.Equals) && transform.localScale.x < 10f) { transform.localScale = new Vector3(transform.localScale.x + Time.deltaTime * speed, transform.localScale.y, transform.localScale.z + Time.deltaTime * speed); } if (Input.GetKey(KeyCode.Minus)) { if (transform.localScale.x > 1f) { transform.localScale = new Vector3(transform.localScale.x - Time.deltaTime * speed, transform.localScale.y, transform.localScale.z - Time.deltaTime * speed); } } } } void OnMouseDown() { flag = true; } }