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 GideonDeJong · Feb 21, 2013 at 07:20 PM · errortransformjavakey

UnityScript error in transform.Position

Hi, This has probably been asked a million times already but i cant seem to find the answer anywhere. I am trying to write a script so that my camera moves to a new angle when a button is pressed, however i keep getting the error :"An instance of type 'UnitEngine.Component is required to access non static member 'transform'. I get this error with both the rotation and position of the camera. This is my code:

 var camera = GameObject.Find("Camera");
 function Update() {
     if (Input.GetKeyDown(KeyCode.D))
         {
         Camera.transform.Position = Vector3(0,11,17.78);
         Camera.transform.Rotation = Vector3(0,180,40);
         }
 }

Hope anyone can help me with htis and thanks in advance :)

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
1
Best Answer

Answer by Posly · Feb 21, 2013 at 07:26 PM

Hm first I would attach this code right on to the camera, so you dont have to use "var camera = GameObject..." instead you can just use "transform.position". Everything in line 5 looks okay you just have to make the p in position lowercase. As for line 6 try using "EulerAngles" instead of Rotation. Hope this helps!

function Update () {
if(Input.GetKeyDown(KeyCode.D))
{
transform.position = Vector3(0, 11, 17.78);
transform.EulerAngles = Vector3(0, 180, 40);
}
}
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 GideonDeJong · Feb 21, 2013 at 09:39 PM 0
Share

Thanks for the quick response, this was really helpful and i got it fixed now. :) EDIT: The camera is now moving to the correct position but does not seem to rotate, even if i use "EulerAngles". Would you be so kind to take a look at my new code? Thanks in advance.

 function Update() {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.D))
         {
         transform.position = Vector3(0,11,17.78);
         transform.EulerAngles = Vector3(0,0,0);
         }
 }
 
avatar image Bunny83 · Feb 22, 2013 at 12:00 AM 0
Share

It should be

 transform.eulerAngles
avatar image
1

Answer by Eric5h5 · Feb 21, 2013 at 07:45 PM

You need to pay attention to spelling and capitalization. You have a variable called "camera" but you're referring to "Camera", which are two different things. If you look in the docs, you can see that there are no properties of Transform called "Rotation" or "Position". (Also, Transform.rotation is a quaternion and does not take a Vector3.)

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

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

12 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

Related Questions

Gun Script Error (Fixed!!!) 1 Answer

Expand script to stop camera from following player 2 Answers

Error Java script 1 Answer

transform.parent can't go with gameObject.find 3 Answers

Facebook Hash key error 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