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 DarkFang100 · Jan 19, 2018 at 03:47 AM · rotationplayerflashlighthorror

How to make a flashlight (childed to the player) rotate with the player?

So I'm making a hospital horror game and was trying to figure out how to make the flashlight rotate up and down as the player rotates up and down (same x rotation, basically), but the script says that when I try to set the flashlight's rotational x value (this is in fixed update by the way) equal to the player's rotational x value, the error given is this:

"Assets/Scripts/FlashlightLook_Y.cs(12,22): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.rotation'. Consider storing the value in a temporary variable"

I don't know how this works or how to correct the error, so someone please give me some help and tell me how to do this. Thanks in advance! Also P.S. maybe we could work together?? IDK it's just an idea but thanks a ton!!

Comment
Add comment · Show 4
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 Mehul-Rughani · Jan 19, 2018 at 04:09 AM 0
Share

Hello, As per your error you can not directly assign any value to transform. for example: you can not do

 transform.rotation.x=12

you have to take one variable and then assign that variable to transform.rotation for example:

 Quaternion tempRotation = transform.rotation;
 tempRotation.x=12;
 trasform.rotation = tempRotation;


Hope you are looking for this. :)

avatar image raoul_95 · Jan 19, 2018 at 04:43 AM 0
Share

Quaternion x=transform.rotation;

//you cannot do like this x.y=90f;

//Ins$$anonymous$$d x=new Quaternion(x.x,90f,x.z,x.w);

avatar image DarkFang100 · Jan 23, 2018 at 02:56 AM 0
Share

@$$anonymous$$ehul-Rughani you should've put that as a reply not a comment and also thanks for the suggestion but I am working with dev-waqas' reply to see if his is any good.

avatar image DarkFang100 · Feb 01, 2018 at 04:02 AM 0
Share

I already found the problem. I childed the flashlight to the camera. Thanks though.

1 Reply

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

Answer by dev-waqas · Jan 19, 2018 at 05:09 AM

You need to store value of rotaion in some variable first.

 var rot= transform.rotaion;

Then you can change value of

 rot.x = player.x;

Don't forget to reassign value to the rotation.

 transform.rotation = rot;


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 DarkFang100 · Jan 23, 2018 at 02:53 AM 0
Share

@dev-waqas Where do I put those sentences of code? Like, in Update, at the start (behind function start), in Start (function start)? Sorry, it's not clear the way you put it. $$anonymous$$aybe you could paste the whole script for me? Thanks for the suggestion though. If you can specify what you mean, I'll accept your reply. :D

avatar image KittenSnipes · Feb 01, 2018 at 02:10 AM 0
Share

Try putting it in the Update method

avatar image DarkFang100 · Feb 01, 2018 at 04:02 AM 0
Share

@dev-waqas @$$anonymous$$ittenSnipes I'm sorry guys but I realised that I had to do put the flashlight under the camera and now it works. Thanks for your suggestions though!

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

113 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

Related Questions

How to disable Mouselook with the new Unity 5? 1 Answer

Rotating objects to specific angle 3 Answers

eulerAngles.y always returns 179.9999 1 Answer

Rotate Locally Player Towards Joystick/Axis Input 1 Answer

Stopping object rotating at a certain rotation 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