Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jmparavicini · Oct 03, 2014 at 01:59 AM · c#javamatrix

Translating gui.matrix to java problem

Hello everyone

I have this script of gui.matrix and it works great but its for c++ and i did my whole project in java and i cant just change it so i ask if someone knows how to translate the script i really tried everything but it just doesnt do anything

Script:

   Matrix4x4 transformation = Matrix4x4.TRS(
         Vector3.zero,
         Quaternion.identity,
         Vector3.one);   
  
     void OnGUI() {
 // We need to assign the GUI matrix before GUI controls are shown.
         GUI.matrix = transformation;
  
         if (GUI.Button(new Rect((Screen.width - 250) / 2, (Screen.height - 100) / 2 - 55, 250, 100), "TRANSFORM GUI")) {
             transformation = Matrix4x4.TRS(
                 new Vector3(-Screen.width * 0.2f, -Screen.height * 0.7f, 0),    // move the GUI a little to fit the transformed controls in the screen
                 Quaternion.Euler(0, 0, 15),    // rotate 15 degrees clockwise around Z, because controls are in XY plane
                 new Vector3(2, 2, 1));  // scale GUI x2 times in X and Y
         }
  
         if (GUI.Button(new Rect((Screen.width - 250) / 2, (Screen.height - 100) / 2 + 55, 250, 100), "NORMALIZE GUI")) {
             transformation = Matrix4x4.TRS(
                 Vector3.zero,
                 Quaternion.identity,
                 Vector3.one);
         }
     }

script made by unimechanic

Thanks in advance Skullbeats1

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Oct 03, 2014 at 02:20 AM

First of all this script is written in C# and not C++ also you are using UnityScript and not Java. The syntax of the relevant parts is exactly the same, you just need to change the declaration of the variable and the method. Also a matrix with no translation, no rotation and a scale of 1.0 is the identity matrix, so you can simply exchange it with the Matrix4x4.identity constant

 var transformation = Matrix4x4.identity;
  
 function OnGUI() {
     // We need to assign the GUI matrix before GUI controls are shown.
     GUI.matrix = transformation;
     
     if (GUI.Button(Rect((Screen.width - 250) / 2, (Screen.height - 100) / 2 - 55, 250, 100), "TRANSFORM GUI")) {
         transformation = Matrix4x4.TRS(
             Vector3(-Screen.width * 0.2f, -Screen.height * 0.7f, 0), // move the GUI a little to fit the transformed controls in the screen
             Quaternion.Euler(0, 0, 15), // rotate 15 degrees clockwise around Z, because controls are in XY plane
             Vector3(2, 2, 1)); // scale GUI x2 times in X and Y
     }
     
     if (GUI.Button(Rect((Screen.width - 250) / 2, (Screen.height - 100) / 2 + 55, 250, 100), "NORMALIZE GUI")) {
         transformation = Matrix4x4.identity;
     }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jmparavicini · Oct 03, 2014 at 02:28 AM 0
Share

You are the best thank you

avatar image jmparavicini · Oct 03, 2014 at 02:45 AM 0
Share

but i have still this error

Ignoring invalid matrix assinged to GUI.matrix - the matrix needs to be invertible. Did you scale by 0 on Z-axis? UnityEngine.GUI:set_matrix($$anonymous$$atrix4x4) GUI $$anonymous$$AN:OnGUI() (at Assets/SCRIPTS/GUI $$anonymous$$AN.js:20)

avatar image Bunny83 · Oct 03, 2014 at 03:27 AM 0
Share

I just tested the script as it is and it works without any errors. You probably have somehow set the matrix in the inspector to the wrong values. The easiest fix is to make your variable private.

Alternatively you can check the values of the matrix in the inspector. All values should read 0 except E00, E11, E22 and E33 which have to be 1. In your case one or more values of the main diagonal (E00, E11, E22, E33) is probably 0.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to move the object at the center of the grid cell? 0 Answers

Pass Matrix4x4 to ComputeShader? 1 Answer

Java - Android - Accessing the /data/data folder 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges