[Unity3D API learning and use] Unity achieves the displacement, scaling, and rotation of GUI components, unity3dunity

Source: Internet
Author: User

[Unity3D API learning and use] Unity achieves the displacement, scaling, and rotation of GUI components, unity3dunity

When using GUI components in Unity, we can perform operations like moving, scaling, and rotating an object.

Here, both displacement and scaling only need to change the Rect content. The former changes the x and y parameters, the latter changes the width and height parameters, and the rotation is different, it requires GUI. A function of matrix:

GUIUtility. rotatearoundity (rotAngle, effectpoint)
Parameter description:
RotAngle: rotation angle;
PivotPoint: the center point around which the image is rotated.

JavaScript example:

# Pragma strictprivate var rotAngle: float = 0; // Rotation Angle private var rotation tpoint: Vector2; // The Center Coordinate function Start () during rotation () {// set the center of rotation to Screen center effectpoint = Vector2 (Screen. width/2, Screen. height/2);} function OnGUI () {if (GUI. button (Rect (Screen. width/2-75, Screen. height/2-100, 50, 50), "right") rotAngle + = 10; if (GUI. button (Rect (Screen. width/2 + 25, Screen. height/2-100, 50, 50), "left") rotAngle-= 10; var matrix: Matrix4x4 = GUI. matrix; // record the current matrix GUIUtility. rotateAroundPivot (rotAngle, rotate tpoint); // rotate if (GUI. button (Rect (Screen. width/2-25, Screen. height/2-25, 50, 50), "Hello") {} GUI. matrix = matrix; // restore the matrix so that the left and right buttons are not rotated}

In the example

Ar matrix: Matrix4x4 = GUI. matrix; // records the matrix at this time.

This line of code records the GUI at this time. matrix, and then it will be restored after the rotation operation (the rotation interface mentioned on the official website is successful by changing the value of this variable, as shown below, so that the left and right buttons are not rotated, but only the Hello button is rotated.

Helper function to rotate the GUI around a point.
Modifies GUI. matrix to rotate all GUI elements angle degrees around tpoint.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.