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 Tahj · Oct 18, 2011 at 11:12 PM · raycastraycastinggrab

Raycast from secondary camera

Hello,

What I am trying to do is create a script that grabs an object by raycasting from a camera embedded within an object. I was trying to restrict it so that it would only effect objects with a specific tag. In this case it is used for a vacuum nozzle. The script I have currently is below but it is getting an error originating on line 5 saying no appropriate version of "UnityEngine.Physics.Raycast" for the argument list '\UnityEngine.Vector3)' was found. So is there a more efficient way to write this code to accomplish this or is there a resource I can look at to help me write a better version of this code?

Thanks in advance for you help.

edit**

So thanks to seeing a little more of the syntax I have changed by code to the below. Although one problem still persists and that is that I cannot get the ray to read objects with the specified tags. Is there something that needs to be done or should I be able to import fbx files into Unity and assign them their tags? So far doing this has resulted in the code printing not working. Is there some step that I for either tagging the objects or within my syntax?

var vacRange = 30.0;

function Update() {

 if (Input.GetKeyDown(KeyCode.E)){
     var hit : RaycastHit;
     if(Physics.Raycast(transform.position, transform.forward, hit, vacRange)) {
         print("hit something");
         if(hit.collider.gameObject.tag=="Food"){
             print("hitting food");
         }else{
             print("not working");
         }
     }
 }

}

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
0

Answer by DaveA · Oct 18, 2011 at 11:33 PM

Physics.Raycast needs more arguments than just position, check the manual

Comment
Add comment · Show 3 · 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 Tahj · Oct 19, 2011 at 01:09 AM 0
Share

By manual are you referring to the support section on the unity main site?

avatar image Bunny83 · Oct 19, 2011 at 02:32 AM 0
Share

By manual he's referring to this which leads to the scripting reference which is located on the unity homepage in the support section

http://unity3d.com/support/documentation/ScriptReference

avatar image Tahj · Oct 19, 2011 at 08:30 AM 0
Share

Very helpful indeed, thanks, but now I can't seem to get it to work based on tagged objects.

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

why Physics.Raycast is not working 1 Answer

Raycasting2D to Compare Tag of GameObject 1 Answer

How to Limit Input.mousePosition or Raycast 1 Answer

How do I measure how far from the normal a raycast is when hitting a surface? 0 Answers

Raycast returns null for no apparent reason 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