Version: 2020.1
public Vector2 position ;

描述

矩形的 X 和 Y 位置。

这与 min 相同,只不过设置它会移动矩形而不是调整其大小。

using UnityEngine;

// Show Rect, the position selected randomly.

public class RectExample : MonoBehaviour { private Rect rect;

void Start() { rect = new Rect(600 * Random.value, 450 * Random.value, 200, 150); }

void Update() { if (Input.GetKeyDown("space")) { rect.position = new Vector2(600 * Random.value, 450 * Random.value); } }

// display a rectangle void OnGUI() { GUI.Box(rect, ""); } }