Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Polygon Tree · Jun 08, 2016 at 07:38 PM · raycastmouseraycastingmousepositionplane

Can't call raycast on plane to get mouse position? Beginner Question

I'm trying to run the sample code from the API here: http://docs.unity3d.com/ScriptReference/Plane.Raycast.html

But it doesn't run. Why can't I call .Raycast on the groundPlane?

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     public Plane groundPlane;
     public Transform markerObject;
     void Update() {
         if (Input.GetMouseButtonDown(0)) {
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             float rayDistance;
             if (groundPlane.Raycast(ray, out rayDistance))
                 markerObject.position = ray.GetPoint(rayDistance);
             
         }
     }
 }

Yields the following error: Assets/Scripts/Player/old/ExampleClass.cs(11,41): error CS1061: Type Plane' does not contain a definition for Raycast' and no extension method Raycast' of type Plane' could be found (are you missing a using directive or an assembly reference?)

Some online tutorial code also yields a similar set of errors? For starters, when initializing the plane, I can't pass the two parameters, when the API says I can?

 Ray ray = viewCamera.ScreenPointToRay (Input.mousePosition);
         Plane groundPlane = new Plane (Vector3.up, Vector3.zero);
         float rayDistance;
 
         if (groundPlane.Raycast(ray,out rayDistance)) {
             Vector3 point = ray.GetPoint(rayDistance);
             Debug.DrawLine(ray.origin,point,Color.red);
             //Debug.DrawRay(ray.origin,ray.direction * 100,Color.red);
             controller.LookAt(point);
         }

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 FortisVenaliter · Jun 08, 2016 at 07:47 PM

Hmmm... I just checked, and the function does exist... and it should work with the code you've provided. Do you have any other scripts called "Plane" that may be conflicting?

Also, I note that the file you are editing is in: Assets/Scripts/Player/old/

Could that be a file you tried to deprecate?

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 Polygon Tree · Jun 08, 2016 at 07:59 PM 0
Share

Wow, utterly total rookie mistake. Had an old script named Plane hidden in a folder above (was trying to make a flying plane to learn Unity!).

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Shoot towards mouse except mouse y 1 Answer

My Ray is going the wrong way 1 Answer

Move object to mouse position 1 Answer

Raycast not drawing where i tell it 1 Answer

how to make a objesc follow the mouse in the 3d world,how to make a object follow the mouse on the 3d world 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