Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ShiroTenshin · Mar 31, 2018 at 08:53 PM · cameracamera rotatefirst person

How can I rotate the camera in 90° with pressing one button?

Just as the question says. I would like to rotate the camera horizontally with 90° with pressing one button. I just can't figure it out. (I'd like to state that i'm a newbie, and I do not know much) The game is 3D, first person mode.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by gonzalezc9999 · Mar 31, 2018 at 11:37 PM

Here is an example that I think might work but you will have to fill in the spots I put as camera with what you named your camera.

using UnityEngine;

Name of Script {

public Transform camera; public float speed = 90

void Update () { if(Input.GetButton("TurnCamRight")) You will have to put in the name of the button used to turn the camera { camera.rotation(0f, speed, 0f); //Turning it Right } if(Input.GetButton("TurnCamLeft")) { camera.rotation(0f, -speed, 0f); //Turning Left } } }

This is the best I can think of.

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 ShiroTenshin · Apr 08, 2018 at 08:52 AM 0
Share

Okay, I'll try it with this. Thank you for the answer. ^^ (Btw: I've came back several times, but somewhy I didn't see your reply.)

avatar image ShiroTenshin · Apr 08, 2018 at 10:24 AM 0
Share

it doesn't seem to work.alt text

Any idea how to fix it? :) (It also says: "The member UnityEngine.Transform.rotation' cannot be used as method or delegate" and: "Cameracontrol.camera' hides inherited member `UnityEngine.Component.camera'. Use the new keyword if hiding was intended" )

asd.png (150.5 kB)
avatar image donutLaserDev ShiroTenshin · Apr 09, 2018 at 09:18 AM 0
Share

It's supposed to be camera.Rotate ()

avatar image
0

Answer by Remy_Unity · Apr 09, 2018 at 11:56 AM

Blind code written here : put this in your update function :

 // Use GetButtonDown to only make the condition valid at the frame where it is pressed
 if (Input.GetButtonDown("My Button Name" )
 {
     // Provide the camera variable the way you want, either by a public variable, or you can use Camera.main to affect the main camera of your game
     camera.transform.Rotate(0, 90, 0);
 }

For more information for the Rotate function look at the API : https://docs.unity3d.com/ScriptReference/Transform.Rotate.html

Comment
Add comment · Show 2 · 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 ShiroTenshin · Apr 28, 2018 at 07:11 PM 0
Share

I feel like we are getting closer step by step. alt text

unity.png (158.2 kB)
avatar image Remy_Unity ShiroTenshin · Apr 30, 2018 at 04:12 AM 0
Share

Well, the error is obviously explained in the console : the variable "camera" has not been assigned.

And like I stated in the comment of my code : // Provide the camera variable the way you want, either by a public variable, or you can use Camera.main to affect the main camera of your game

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

127 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 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 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 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 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

Best way to rotate child and parent game objects in different axes without the rotation going crazy or glitchy? 1 Answer

Rotating first person camera on y axis not working? 1 Answer

FPS Camera Control rotation limits 1 Answer

Camera gets stuck when cursor is locked 0 Answers

First Person Camera looking down 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