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 mewhy · Mar 04, 2013 at 05:20 AM · errorcomponent

Problem getting GetComponent to work

hello, i just had a quick question. i am trying to access a variable from a script attached to my main camera here is the code.

 Camera.main.GetComponent<camera>().target = myship.transform;

i have tried multiple different ways and it still comes up with this error.

Assets/Scripts/NetworkManager.cs(25,42): error CS0246: The type or namespace name `camera' could not be found. Are you missing a using directive or an assembly reference?

can someone tell me what i am doing wrong.

thank you, mewhy

Comment
Add comment · Show 2
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 robertbu · Mar 04, 2013 at 05:22 AM 1
Share

Is your script named "camera"? The name of the script needs to be inside the angle brackets.

avatar image liamcary · Mar 04, 2013 at 05:41 AM 0
Share

If it's the unity Camera component you're trying to access, it has a capital 'C'.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kronos312 · Mar 04, 2013 at 07:32 AM

try this

if u have a gameobject named "Camera" and script named "camera"

 GameObject MyCamera = GameObject.Find ("Camera"); //fetch the object
 if (MyCamera==null) print ("Could not find the object Camera"); 
 camera cameraScript = MyCamera.GetComponent<camera>(); // this is mainly to check what is your problem
 if (camera==null) print ("Cant find my script camera");  // use this line OR the next line
 MyCamera.GetComponent<camera>().target = myship.transform; // or use this line this is your line
 // camera.target = myship.transform // if you have the script like here in this exmaple.


after this you should be able to understand where is your problem. good luck.

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 mewhy · Mar 04, 2013 at 05:18 PM 0
Share

Thanks $$anonymous$$ronos312, the only problem is it comes up with the compile error Before i can print anything to the console. it is kinda weird. do you think you could give me a JS version of this so i can see if that is the problem?

avatar image mewhy · Mar 04, 2013 at 05:31 PM 0
Share

Ok I converted this into JS just to test it and my problem is that it cannot find the script named camera. could someone help me out?

avatar image
0

Answer by mewhy · Mar 04, 2013 at 06:08 PM

HEY I GOT IT!!!! read this and you will see what my problem was. http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html

Comment
Add comment · Show 1 · 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 mewhy · Mar 04, 2013 at 06:05 PM 0
Share

i was trying to access a JS from C# BTW.

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

Unity cannot find component of an object in an array. 2 Answers

can't create new project , can't find component 0 Answers

Object Reference not set to instance of object 2 Answers

An instance of type 'UnityEngine.Animator' is required to access non static member 'GetBool' 1 Answer

Modifying components of an array 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