"Learning and using the Unity3d API" unity implements the displacement, scaling, and rotation of GUI components

Source: Internet
Author: User

When using the GUI components in unity, we can shift, scale, and rotate them as we do with an entity.

where displacement and scaling only need to change the contents of their rect, the former changes the x, y parameters, the latter changes the width and height parameters, and the rotation is different, it needs to use a function of Gui.matrix:

Guiutility.rotatearoundpivot (Rotangle, Pivotpoint)
Parameter description:
Rotangle: angle of rotation;
Pivotpoint: The center point around which the rotation occurs.

JavaScript Example:

#pragma strictPrivate varRotangle:float =0;//Angle of rotationPrivate varPivotpoint:vector2;//Center coordinate when rotating function Start(){    //Set Rotation center point to screen centerPivotpoint = Vector2 (screen.width/2, screen.height/2); } function Ongui () {    if(GUI. Button (Rect (screen.width/2- the, screen.height/2- -, -, -),"Right")) Rotangle + =Ten;if(GUI. Button (Rect (screen.width/2+ -, screen.height/2- -, -, -),"left")) Rotangle-=Ten;varmatrix:matrix4x4 = Gui.matrix;//Record The matrix at this timeGuiutility.rotatearoundpivot (Rotangle, pivotpoint);//Rotate    if(GUI. Button (Rect (screen.width/2- -, screen.height/2- -, -, -),"Hello") {} Gui.matrix = matrix;//matrix recovery so that the left and right buttons do not rotate}

In the example

matrix : Matrix4x4 = GUI.matrix;              //记录此时的矩阵

This line of code is to record the Gui.matrix of the GUI interface at this point, and then restore it after the rotation operation (the website says that the rotation interface is successful by changing the value of the variable, such as the following), 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 pivotpoint.

"Learning and using the Unity3d API" unity implements the displacement, scaling, and rotation of GUI components

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.