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 ArunChnadran · Jan 24, 2012 at 01:29 PM · rotation

Rotate around Pivot.

A newbie here. What exactly am I trying to do is, rotate the cubes when I press the circle in the center. The first position of the cubes will be like in the figure one and when the circle is pressed then the cubes rotate with pivot point as the center of the circle. The cubes are just for informative purpose only, when the artist comes it will change to insects, that is why the 'cube A' in the second figure is lying down! (And also the cubes are individual there will be many other cubes and circles and also blank spaces in the grid ). Can any please guide me how to do this? alt text

alt text

As the first step I'm just trying to rotate one cube and after completing 90degree I am trying to display it. And that is also not working, but here goes my code:-

 var yflower:Texture2D;
 var bflower:Texture2D;
 var flowerRect:Rect = Rect(100, 100, 100, 100);
 var pivotPoint:Vector2=Vector2(100, 100);
 var rotAngle=0;
 //var firstCycle:boolean=false;
 //var pivotPoint2:Vector2=Vector2(220,220);
 var flowerRect2:Rect = Rect(0, 300, 300, 100);

 function OnGUI () 
 {    
 //    GUI.DrawTexture(flowerRect, yflower, ScaleMode.ScaleToFit,true, 0);
     if (rotAngle<90)
     {
         GUIUtility.RotateAroundPivot(rotAngle, pivotPoint);
         GUI.DrawTexture(flowerRect, yflower, ScaleMode.ScaleToFit,true, 0);
         rotAngle++;
     
     }
     else if(rotAngle>=90)
     {
         GUI.DrawTexture(flowerRect2, yflower, ScaleMode.ScaleToFit,true, 0);
         Debug.Log("bflower");
     }
 }

Its rotating once and disappears. :-(!!

Comment
Add comment · Show 3
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 ArunChnadran · Jan 24, 2012 at 01:42 PM 0
Share

image links are not working, I think! So here are the links:- Figure One:- http://postimage.org/image/c6egw05bz/ Figure Two:- http://postimage.org/image/yttq25kvz/

avatar image syclamoth · Jan 24, 2012 at 01:53 PM 0
Share

Could you make the images flat planes in front of the camera, and then rotate them using transform.rotation? In my experience, trying to rotate elements in the GUI system in a consistent and sane way is surprisingly difficult.

avatar image ArunChnadran · Jan 24, 2012 at 02:40 PM 0
Share

Currently the game is not completely designed and I am in constant communication with my artist (should go for 2D/3D). So I thought I'll try out 2D first, then I came up with this GUITexture and stuffs. According to my plan these cubes will be inscets and plants and stuffs like that and 2D/3D does depends on the budget. I do prefer 3D. So'll roll back to you after trying. thnx for the tip!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by IJM · Jan 24, 2012 at 01:56 PM

You can use this to check for click:

 var rect = Rect (0, 0, 150, 150); // Rect around your circle
 if (rect.Contains(Input.mousePosition))
    if(Input.GetMouseButtonDown(0))
      //Do something on left click

To rotate your texure, you can do this:

 var matrixBackup = GUI.matrix; // U need to save your original matrix
 GUIUtility.RotateAroundPivot(angle, pivot); // In your case, angle will lerp from 0 to 90
 GUI.DrawTexture(rect, texture);
 GUI.matrix = matrixBackup; // And restore it at the end
Comment
Add comment · Show 5 · 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 ArunChnadran · Jan 24, 2012 at 03:13 PM 0
Share

hmmm... Ivan, Can you please tell me what this matrix is for? And when I tried with your code I got some other place as pivot point. var pivot:Vector2=Vector2(150, 150); but that was not my pivot point. Thanx for the hands!

avatar image IJM · Jan 24, 2012 at 06:40 PM 0
Share

No it is not. You have to use same rect for your texture, "rect.Contains" call, and your pivot. To calculate the center of a rect you can do this: var pivot:Vector2=Vector2(rect.x + rect.width/2, rect.y + rect.height/2); In 3D computer graphics, 4x4 transformation matrices are used to position/rotate/scale objects. Np. mate, any time :D

avatar image ArunChnadran · Jan 25, 2012 at 04:11 AM 0
Share

But mate here I'm trying to rotate 90deg first and then pause until there is a response from the user. And again my first pivot point will be bottom right for the first press and then for the second press the bottom left will be the pivot point. Then for the third press it will be top left. And $$anonymous$$I didn't understand the usage of matrix here.

avatar image syclamoth · Jan 25, 2012 at 04:34 AM 0
Share

Ok. I think it'd definitely be easier just to use planes with textures on them. The matrix is what transforms between the x-y coordinates of the gui system (where you put textures and other elements) and the x-y coordinates of the screen. You can use it to rotate and scale gui elements, but as I've said it's difficult to animate them in the way that you seem to need.

avatar image ArunChnadran · Jan 25, 2012 at 08:02 AM 1
Share

rotating a cube is easier than rotating a GUITexture2D. Thanx syclamoth.

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

6 People are following this question.

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

Related Questions

fbx animation beats script animation? 2 Answers

Rotate around a pivot between two points? 2 Answers

How to make a script access animations from a child prefab 1 Answer

wrong rotation in animation per script 0 Answers

when Rotateing direction prob 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