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 solo24601 · Apr 18, 2012 at 01:11 PM · cameraguibuttoncontrollerzoom

Moving camera around with GUI buttons

Howdy all,

I have a VERY simple GUI that moves my main camera through my scene. It functions by having a camera that is a child of a sphere in the scene. The sphere is caused to rotate by the GUI and the camera then moves, focused on the sphere. This is in no way ideal, but I am a a short time frame and its the best a beginner can come up with. I am wondering now, how would I add a zoom function to the following GUI:

Code:

  var imageLeft: Texture2D;
  var imageRight: Texture2D;
  var imageUp: Texture2D;
  var imageDown: Texture2D;
  var speed: float = 60;
  private var rotLeft = false;
  private var rotRight = false;
  private var rotUp = false;
  private var rotDown = false;
  var w1:float;
  var x1:float;
  var y1:float;
  var z1:float;
  var w2:float;
  var x2:float;
  var y2:float;
  var z2:float;
  var w3:float;
  var x3:float;
  var y3:float;
  var z3:float;
  var w4:float;
  var x4:float;
  var y4:float;
  var z4:float;
  function OnGUI(){
  rotLeft = GUI.RepeatButton(Rect(w1,x1,y1,z1),

imageLeft); rotRight = GUI.RepeatButton(Rect(w2,x2,y2,z2), imageRight); rotUp = GUI.RepeatButton(Rect(w3,x3,y3,z3), imageUp); rotDown = GUI.RepeatButton(Rect(w4,x4,y4,z4), imageDown); }

  function Update(){    
  if (rotLeft) transform.Rotate(0, -speed*Time.deltaTime, 0);
  if (rotRight) transform.Rotate(0, speed*Time.deltaTime, 0);
  if (rotDown) transform.Rotate(0, 0, speed*Time.deltaTime);
  if (rotUp) transform.Rotate(0, 0, -speed*Time.deltaTime);
  }


Or if anyone has any other suggestions for a GUI based controller I would be glad to hear them. The idea though is that the camera will orbit an object and constantly be looking at it. The only reason there are so many variables for the positioning of the buttons is aesthetics. I like to be able to move things around to see where they look best.

Thanks a ton, Richard

Comment
Add comment · Show 2
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 bodec · Apr 18, 2012 at 07:24 PM 0
Share

I believe there is a effect that can be uswd to smooth it out but i cant look it up Tm as i am not at home

avatar image nicholasfsoares · Sep 06, 2012 at 01:14 PM 0
Share

tip:

When using variables to store x and y position, width and height dimensions, even for several rectangles ins$$anonymous$$d of one variable for each item, use for example:

var pos1: Vector2; (which comes with attributes x and y) var dim1: Vector2; (using x and y with width and height)

or

var rect1: Rect, you already defines a rectangle.

and when several values ​​vectors use at least

var pos: Vector2 []; var dim: Vector2 [];

var rectangle: Rect [];

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bodec · Apr 18, 2012 at 02:21 PM

I beleave another if statement with something down the Z axis would be neededusing the transform.position.z(or the X) and then just set up by how much .5 perclick or on a repeat button like you have.

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
0

Answer by solo24601 · Apr 18, 2012 at 05:09 PM

Thanks for responding. Yeah, I'm trying to make it smooth. But so far I have only been able to make it move very jittery and jumpy. Not really adept at writing code as you can see.

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 HomeSpunGames · Apr 18, 2012 at 08:37 PM 0
Share

Try $$anonymous$$athf.Lerp to smooth the movements.

avatar image
0

Answer by solo24601 · Apr 19, 2012 at 08:13 PM

Thanks, HomeSpun. Will do. And when I get this figured out I will post the full code here.

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
0

Answer by solo24601 · Apr 19, 2012 at 08:13 PM

Thanks, HomeSpun. Will do. And when I get this figured out I will post the full code here.

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

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

pan camera by touch / gui button 0 Answers

Making GUI Buttons on a GUI Texture 1 Answer

Clicking Trigger 1 Answer

How to stretch a GUI texture over it's original size? 1 Answer

flickering lines when zooming fov (both GUI and ortho cameras). 2 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