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 kaiyum · Feb 17, 2014 at 03:31 PM · gameobjectcamera.screentoworld

accessing camera from anther gameobject, not working

Hi, I tried the following code on update(),

 convertedVector=GameObject.FindGameObjectWithTag("camera").GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,camera.nearClipPlane+10.0f));

But unity is giving me a error like this,

 MissingComponentException: There is no 'Camera' attached to the "whatTheFuck" game object, but a script is trying to access it.
 You probably need to add a Camera to the game object "whatTheFuck". Or your script needs to check if the component is attached before using it.
 gameobjtest.Update () (at Assets/scripts/gameobjtest.cs:15)


camera is attached to a gameobject tagged "camera" and the refering script is attached to a gameobject called "whatTheFuck". Now I am not trying to access any camera attached to "whatTheFuck" gameobject, rather I am trying to access camera from another gameobject. But unity is saying me electric. What is causing the problem?

Comment
Add comment · Show 6
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 DoctorSauce · Feb 17, 2014 at 03:48 PM 0
Share

I think "whatTheFuck" probably has the tag "camera".

avatar image kaiyum · Feb 17, 2014 at 03:53 PM 0
Share

no it is untagged. Only the gameobject named "camera" has the tag "camera". No other gameobject has this tag. And "camera" gameobject has a "Camera" component where there is a orthographic skybox camera attached to it.

avatar image Olgo · Feb 17, 2014 at 04:03 PM 0
Share

you said "camera is attached to a gameobject tagged "camera" and the refering script is attached to a gameobject called "whatTheFuck"" ...

Do you mean to say the camera is its own GameObject and tagged "camera" or there is a gameobject with tag "camera" and a camera is its child? If so, I would do away with the parent object and just tag the Camera object as camera

avatar image kaiyum · Feb 17, 2014 at 04:28 PM 0
Share

camera is its own GameObject and the gameobject is tagged as "camera".

avatar image kaiyum · Feb 17, 2014 at 04:29 PM 0
Share

Oh I got it. The main problem was "camera.nearClipPlane" part.

Show more comments

2 Replies

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

Answer by kaiyum · Feb 18, 2014 at 10:44 AM

The main reason of why my code did not work is because of:

 camera.nearClipPlane+10.0f

Here nearClipPlane is referring to clip plane of this gameobject's camera component. But there is no camera attached to this gameobject. Camera is attached to a gameobject with camera tag. So we have to refer that gameobject. Thus in stead of using:

 camera.nearClipPlane+10.0f

We have to write like,

 GameObject.FindGameObjectWithTag("camera").GetComponent<Camera>().nearClipPlane+10.0f;


This will work just fine.

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
0

Answer by JP3ACE · Sep 28, 2016 at 08:43 PM

I know I am late, but I think I just figured it out.

Make sure the Game Object you want to see through has the "Player" Tag

Also,

Make sure the camera attached to that Game Object has the "Main Camera" Tag

It just worked for me, no need to write extra code, no errors. Hope this helps!

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

22 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

OnCollisionEnter GameObject throws NullReferenceException 0 Answers

About Destructible 3d objects 1 Answer

Don't Destroy on Load Object and GameData 1 Answer

"Transform" still trying to access after Destroy 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