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 /
This question was closed Jan 16, 2015 at 11:50 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by ShadowBroker · Apr 28, 2011 at 08:09 PM · euleranglesconverting

Set eulerAngles to c#?

I try to write my scripts from now on in c# instead of javascript and have some little problems converting a script.

transform.eulerAngles.x = Camera1.eulerAngles.x - 90;

I always get the error that I can't set eulerAngles.x because it isn't a variable. How can I set a single Angle in c#?

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

  • Sort: 
avatar image
10
Best Answer

Answer by Mortennobel · Apr 28, 2011 at 08:12 PM

Vector3 tmp = transform.eulerAngles;
tmp.x = Camera1.eulerAngles - 90;
transform.eulerAngles = tmp;

Reason: The eulerAngles is a property, and you cannot set only part of a property (transform.eulerAngles.x would invoke the getter method - which cannot be used as a setter). In other words: You need to use a temporary variable to do what you want to do :-)

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 MinorMapillai · Feb 15, 2019 at 09:54 PM 0
Share

Is it the same for the y angle? I just need to change the .x to .y?

avatar image dan_wipf MinorMapillai · Feb 16, 2019 at 09:53 AM 0
Share

yes it is.

avatar image
3

Answer by Antony-Blackett · Apr 28, 2011 at 08:15 PM

I think c# is a little strange in that you can't set a property on a property of an object if the first property is a value type. Do this instead.

Vector3 eulerAngles = transform.eulerAngles;
eulerAngles.x = Camera1.eulerAngles.x - 90;
transform.eulerAngles = eulerAngles;
Comment
Add comment · Show 4 · 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 Antony-Blackett · Apr 28, 2011 at 08:17 PM 1
Share

The above answer explains it better.

avatar image ShadowBroker · Apr 28, 2011 at 08:20 PM 0
Share

But at least you get some reputation points :)

avatar image Antony-Blackett · Apr 28, 2011 at 08:30 PM 0
Share

haha thanks, but not deserved. $$anonymous$$y code was wrong (fixed now) and the $$anonymous$$ortennobel beat me while typing. :P

avatar image MadMenyo · Jan 16, 2015 at 11:23 AM 0
Share

The reason is that the property itself is private so not accessible from your class. They only created a getter to get the property but not a setter. They could probably create a setter for this, but whenever the code for setting this variable changes they have to change it at the base of the class as well and vice versa. Best practice is to have a single access point for setting properties otherwise things might get really messy, here they choose for having transform.eulerAngles as the access point for setting the euler angles x, y and z at once.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

quaternion.eulerAngles 1:1 angle conversion 1 Answer

How do I call a function containing a while loop, inside the update function? 2 Answers

ConfigurableJoint - angular positions (rotation) problem 1 Answer

shaft rotation 1 Answer

Why changing eulerangles causes so much FPS drop? 0 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