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 UnityAuthor20 · May 05, 2018 at 12:07 AM · scripting problemcamera-movement

Rotating Sutff

So, I have a script that rotates based on mouse input. How do I make it so it affects the two gameobject variables in the script rather than the object that the script is attached to?

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

1 Reply

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

Answer by Eno-Khaon · May 05, 2018 at 02:44 AM

Rather than just affecting your current object's Transform, you can simply affect other ones instead through the GameObject variables.

 // C#
 
 public GameObject otherObj1;
 public GameObject otherObj2;
 
 // ...
 
 // Replace something along the lines of...
 transform.rotation = rotationFromMouse;
 // ... with something like:
 otherObj1.transform.rotation = rotationFromMouse;
 otherObj2.transform.rotation = rotationFromMouse;
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 UnityAuthor20 · May 05, 2018 at 12:17 PM 0
Share

@$$anonymous$$o-$$anonymous$$haon thanks, do you know how to move the camera using the mouse? (Just started unity a few months ago)

avatar image Eno-Khaon UnityAuthor20 · May 06, 2018 at 01:08 AM 0
Share

Well, you can get the main camera in a scene using Camera.main, so you can get its transform data from there.

 // C#
 private Transform camTransform;
 
 private void Start()
 {
     camTransform = Camera.main.transform;
 }


From there, modifying its position would be done using the mouse input:

 // simple example, moving camera based on its orientation
 public float mouseX$$anonymous$$ultiplier;
 public float mouseY$$anonymous$$ultiplier;
 
 // ...
 
 private void Update()
 {
     Vector2 mouseInput = new Vector2(Input.GetAxis("$$anonymous$$ouse X") * mouseX$$anonymous$$ultiplier, Input.GetAxis("$$anonymous$$ouse Y") * mouseY$$anonymous$$ultiplier);
     camTransform.position += camTransform.right * mouseInput.x;
     camTransform.position += camTransform.up * mouseInput.y;
 }


Edit: Whoops, forgot to actually apply the mouseInput the way I intended in my example.

avatar image UnityAuthor20 · May 07, 2018 at 08:29 PM 0
Share

@$$anonymous$$o-$$anonymous$$haon I made a mistake, I meant to rotate the camera, not move it. $$anonymous$$y bad. (For an example of what I want, look at the game $$anonymous$$inecraft)

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

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

Clamping Camera doesn't work 1 Answer

setting up different camera views for clients in unity network 0 Answers

Smooth camera script looking at left hand side of character. 0 Answers

Confining Mouse Look on X axis 0 Answers

Multiple Targets Camera 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