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 VIIKnight · Jun 08, 2014 at 03:50 PM · c#errorraycast

How to "Camera.ScreenPointToRay". I get an error in MonoDevelop.

Hello, I am pretty new to Unity. I am trying to cast a ray from the main camera, mouse position into the game world. This video http://www.youtube.com/watch?v=P0PHY1hJp5k shows exactly what I want to do. I have also tried to copy and paste from the Unity script reference page. I thought the unity script reference was supposed to be a working code snippet. When I try either one and to debug them I get the same 3 error messages. The 2 versions of code are..

 void Update () {
     
         Ray ray = Camera.mainCamera.ScreenPointToRay (Input.mousePosition);
         Debug.DrawRay (ray.origen, ray.position * 10, Color.cyan);
     }
     

and

 public class ExampleClass : MonoBehaviour {
     void Update() {
         Ray ray = camera.ScreenPointToRay(new Vector3(200, 200, 0));
         Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
     }

This one is from the Unity script reference. When I try to debug them I get these 3 errors and warning...

  1. Error CS0029: Cannot implicitly convert type 'UnityEngine.Ray' to 'Ray' (CS0029) (Assembly-CSharp).

  2. Error CS1061: 'Ray' does not contain a definition for 'origin' and no extension method 'origin' accepting a first argument of type 'Ray' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp).

  3. Error CS1061: 'Ray' does not contain a definition for 'direction' and no extension method 'direction' accepting a first argument of type 'Ray' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp).

  4. Warning CS0618: 'UnityEngine.Camera.mainCamera' is obsolete: 'use Camera.main instead.' (CS0618) (Assembly-CSharp).

So I understand the Warning. I have Unity version 4.1.5f1 on my other computer and all this code works fine. Running the newest version, how can I make the code work now?

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

1 Reply

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

Answer by robertbu · Jun 08, 2014 at 03:52 PM

You code looks fine. The problem is that somewhere in your project you have created a Ray script or a Ray class. This class is being used when you declare a 'Ray' rather than the Unity Ray class. Rename your class, and the problem will go away.

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 VIIKnight · Jun 08, 2014 at 04:02 PM 0
Share

Wow! Thank you this was it. The only thing that I noticed that didn't work was the difference between "ray.position and ray.direction.". The "ray.direction" was the only one that worked in the end. Thanks again!

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

cant kill more than one enemy C# 2 Answers

Raycast doesn't collide as it should 1 Answer

enemy detect player then attack - c# 1 Answer

NullReferenceError, Tilemap Array with Transforms and Raycast (C# with Demo) 0 Answers

Line Renderer not showing 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