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
1
Question by rhose87 · Oct 27, 2011 at 12:46 PM · rotateguitexture

Rotate object with a gui texture button

i have an object and 2 gui texture buttons. i want to rotate my object by pressing the 2 buttons (one-left, one-right).

ideas ?

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

3 Replies

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

Answer by aldonaletto · Oct 27, 2011 at 01:49 PM

It's simple, use GUI.RepeatButton and transform.Rotate - like this:

var imageLeft: Texture2D; // drag the left button image here var imageRight: Texture2D; // right button image var speed: float = 60; // rotate speed in degrees per second private var rotLeft = false; // object rotates left if true private var rotRight = false; // object rotates right if true;

function OnGUI(){ rotLeft = GUI.RepeatButton(Rect(10,10,200,200), imageLeft); rotRight = GUI.RepeatButton(Rect(230,10,200,200), imageRight); }

function Update(){

 if (rotLeft) transform.Rotate(0, -speed*Time.deltaTime, 0);
 if (rotRight) transform.Rotate(0, speed*Time.deltaTime, 0);

} I don't know which value Time.deltaTime assumes inside OnGUI - it should be the time since last OnGUI, but I'm not sure. To avoid problems, I placed the real rotation in Update and used two control booleans (rotLeft and rotRight) to communicate with OnGUI.

Comment
Add comment · 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
1

Answer by MoyaAdam · Oct 27, 2011 at 01:49 PM

try doing something like this

 function OnGUI(){
 var RotateSpeed:float;   //speed to rotate at
 var MyObject:GameObject; //the object to rotate
 if(GUI.RepeatButton(SomeRect, sometexture)){
 MyObject.transform.rotation.y+=RotateSpeed;
 }
 if(GUI.RepeatButton(SomeOtherRect, someOthertexture)){
 MyObject.transform.rotation.y-=RotateSpeed;
 }
 }

if you want the code in C# ask me, and I dont know if it works, i'll test it when I get home for you

Comment
Add comment · Show 1 · 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 aldonaletto · Oct 27, 2011 at 03:38 PM 0
Share

This is wrong! rotation is a quaternion, and rotation.y isn't the angle around y. You should use eulerAngles ins$$anonymous$$d:

 $$anonymous$$yObject.transform.eulerAngles.y += RotateSpeed;

This will modify the angle around y.
In a quaternion, y is sin(angle/2) * ay where angle is the angle to rotate and ay is the y coordinate of the axis around which the rotation occurs. If you want to fry your brain learning about quaternions, read this article: http://www.gamedev.net/page/resources/_/technical/math-and-physics/quaternion-powers-r1095

avatar image
0

Answer by rhose87 · Oct 27, 2011 at 02:49 PM

can i do this without rect ?

Image

I would like both panels (rotate and zoom) to look the same (as zoom does, witch was done with gui textures).

Comment
Add comment · Show 1 · 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 aldonaletto · Oct 27, 2011 at 03:40 PM 0
Share

I suppose you can draw the background texture with GUI.DrawTexture, then draw the buttons - they will be drawn over the background texture.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotating GUITexture 1 Answer

rotating guiTextures? 1 Answer

Camera rotation around player while following. 6 Answers

Cannot get GUIUtility.RotateAroundPivot working 1 Answer

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer


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