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
0
Question by RaulDiaz · Nov 16, 2010 at 10:49 PM · camerapositiony

Adding y position?

ok i jsut need to move my camera up a few y positions

example

transform.position.y = transform.position.y +90;

Whats wrong with that? if transform is the camera

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

4 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by denewbie · Nov 17, 2010 at 09:05 AM

You could try a tralslation instead.

transform.Translate(Vector3.up * 90, Space.World);
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 denewbie · Nov 17, 2010 at 09:07 AM 0
Share

The Space.World ensures it moves with respect to world. For local translation just use: transform.Translate(Vector3.up * 90);

avatar image Statement · Dec 06, 2010 at 11:32 PM 0
Share

Thanks for enlightening me along the way. I always went for the long version (see my answer). It just struck me how much more elegant your method is :)

avatar image
1

Answer by Statement · Dec 06, 2010 at 11:31 PM

I assume this is C# code. In C#, you can't modify struct fields on properties directly because properties return a copy of the value. It would make no sense to modify a field on a local copy.

I present two options.

As denewbie says:

transform.Translate(Vector3.up * 90, Space.World); 

And the long hand version:

Vector3 position = transform.position;
position.y += 90;
transform.position = position;

You decide what makes the cleanest solution.

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
1

Answer by Uriel_96 · Dec 07, 2010 at 12:22 AM

Why you dont easily put

transform.localPosition.y += 90;
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 Statement · Dec 07, 2010 at 12:26 AM 0
Share

Exact duplicate. It doesn't work in C# either.

avatar image Uriel_96 · Dec 07, 2010 at 12:42 AM 0
Share

O$$anonymous$$, I'm geting confuse, what he wants is this but in C#???

avatar image Uriel_96 · Dec 07, 2010 at 12:46 AM 0
Share

if you need it with C# you only need to see this page http://unity3d.com/support/documentation/ScriptReference/Transform-localPosition.html and change java script to C#

avatar image
0

Answer by Eric5h5 · Nov 16, 2010 at 10:53 PM

Nothing is wrong with it, though you could shorten it by writing

transform.position.y += 90;
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 Proclyon · Nov 17, 2010 at 10:31 AM 0
Share

Cannot modify the return value of 'UnityEngine.Transform.position' because it is not a variable (CS1612)

Does not work in C#

avatar image denewbie · Nov 17, 2010 at 11:47 AM 0
Share

Hi. for C# you cant modify a singe values you have to do it like this:

transform.position = new Vector3(transform.position.x, transform.position.y+90, transform.position.z );

I find it a pain so i just just Translate

avatar image Proclyon · Nov 17, 2010 at 12:08 PM 0
Share

You just double posted my comment here aswell and voted me down on the double answer. Isn't that slightly hypocritical? Ah well whatever. As long as it gets an accepted answer somehow. Cba flamewars

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Strategy camera problems. 0 Answers

how to put like a camera on the enemy so he can see you only in a specific angle? 1 Answer

Camera problem 2 Answers

Toggle map/Camera [JS] 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