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 sriram90 · Mar 10, 2011 at 05:34 AM · iphoneraycasthit

unity iphone raycast problem

hi guys,

i'm trying to make a game in iphone using unity3d....i'm getting trouble when i make touch on the gameobjects...

here is my script....

//.cs

public RaycastHit hit;

void Update() {

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Input.GetMouseButtonDown(0)) { if(Physics.Raycast(ray,out hit,100)) { Debug.Log("hitted object "+hit.transform.gameObject.name);
}

} }

am getting the error as:

NullReferenceException: UnityEngine.Camera.ScreenPointToRay (Vector3 position)

well i have used the same script in my another scene...thats worked perfectly...but now its not working well....in briefly i have attached mesh colliders all of my gameobjects.....

i have a board in my game with mesh collider attached...and lot of coins(like cylinders) in it...i want to touch that coins and wanna to get that coin name....thats it my problem...any one explain what kind of problem i have now.....

thanks.

Comment
Add comment · Show 1
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 sriram90 · Mar 10, 2011 at 07:11 AM 0
Share

hello guys i'm in emerge...please can any one help me....i have searched lot in google...but no luck....

1 Reply

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

Answer by loopyllama · Mar 10, 2011 at 08:20 AM

you probably don't have a camera tagged as "MainCamera" in the scene with the error and you have a camera tagged as "MainCamera" in the scene in which the script works. Just open the scene in which the error occurs, select the camera, and select "MainCamera" in the Tag property.

You can easily test this in script by commenting out your code and adding this line to your Update():

print ("My main camera is: " + Camera.main.name);

My guess is you will get a similar error.

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 sriram90 · Mar 10, 2011 at 08:44 AM 0
Share

ya....thats awesome....thank you harmless...perfect answer...

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

Help with DPAD Input Touch For Mobile 0 Answers

iPhone Touch RayCastHit problem 2 Answers

Raycashit Variable make empty/null/clear? 1 Answer

Unity3D 3.X generates a iPhone_target2AppDelegate? Use? 0 Answers

Unity iPhone 2D Left Right movement 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