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 Louis 1 · Sep 03, 2010 at 08:04 AM · camerabuttonpositionmoveclick

button click to move camera to another position

hi, i want to move my camera when i click on a button. my button is a plane and has a OnMouseDown on it. However, i can't assign the gameobject as my camera. so im not sure even if my codes do work. here is my code. im new to unity so im not sure if it's right or wrong.

Thanks to anyone who can help and really sorry for the trouble.

var player : GameObject;

function OnMouseDown () { player.transform.Translate(1,1,1);

}

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 · Sep 03, 2010 at 08:16 AM 0
Share

No need to apologise! One small request - when posting code, highlight it and press the icon with 0s and 1s on it, and it will format nicely. Not much of an issue here where the code is so compact, but with bigger examples it becomes difficult to read. Cheers!

avatar image Louis 1 · Sep 09, 2010 at 02:05 AM 0
Share

ok. noted.. thanks for the help =)

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by · Sep 03, 2010 at 08:14 AM

OnMouseDown is only called when the user has pressed the mouse button while over the GUIElement or Collider. I think you want GetMouseButtonDown. You can also access the main camera via Camera.main.

function Update ()
{
   if (Input.GetMouseButtonDown(0))
   {
      Camera.main.transform.Translate(1,1,1);
   }
}
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 diabloroxx · Oct 16, 2010 at 06:27 AM

Your code is correct. Just make sure that you add a collider to the Plane (which you want to assign as a button). You can also add a GUI button to translate or move your camera. That way your button will always be in view. I assume you will not want to move the Plane along with your camera.

Add collider by going to Physics and then collider.

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

No one has followed this question yet.

Related Questions

how to have an object positioned relative to the screen(like a button) 1 Answer

Camera not moving on mobile 0 Answers

Move to a clicked point? 1 Answer

how would i create a button that animates the main camera when clicked? 1 Answer

Moving object to according where camera is looking 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