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 Mark981 · Oct 16, 2012 at 05:43 PM · raycastplayer

Raycast Destroys player.

Hi,i want my player destroys when he touches raycast,i dont know anything about raycast,so may i ask script example? Please?

Comment
Add comment · Show 4
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 Loius · Oct 16, 2012 at 06:47 PM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

avatar image Mark981 · Oct 16, 2012 at 06:49 PM 0
Share

how it works,like: destroy (gameobject)-its player then action is happening with player,please can you explain me, i dont know anything.

avatar image Jep · Oct 16, 2012 at 07:04 PM 0
Share

Think of a Raycast as simply a Line with an Origin(starting point), Distance, and Direction. It's basically a hit test.

So when you test if the Ray(or line) collides with the target object and if it does, you can do whatever such as destroy the game object.

The documentation posted above explains with examples.

avatar image Mark981 · Oct 16, 2012 at 07:08 PM 0
Share

Well its not posted what i need,well just destroy player and thats all,with that Destroy(gameobject)

1 Reply

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

Answer by MibZ · Oct 16, 2012 at 07:10 PM

 Ray rayToCast = Camera.main.ScreenPointToRay(screenPosition);
 RaycastHit hit;
 
 //When out is placed in front of a function parameter the variable passed in is also returned, so the RaycastHit "hit" is given data from the Physics.Raycast function, and after the function has finished running you can check "hit" for information related to what the ray collided with.
 Physics.Raycast(ray, out hit);
 
 if (hit.collider != null)
 {
    //If hit.collider isn't null, that means the ray collided with a GameObject that has a Collider (box collider, sphere collider, mesh collider, etc)
    //You can reference the GameObject the collider is attached to by using "hit.collider.gameObject" 
    //In case you don't know, uppercase 'G' GameObject is the type, while lowercase 'g' gameObject allows you to reference the GameObject a component is attached to. 
 
    if (hit.collider.gameObject.tag == "Player")
       Destroy(hit.collider.gameObject);
 }
Comment
Add comment · Show 2 · 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 Mark981 · Oct 16, 2012 at 07:13 PM 0
Share

Ok thanks :)

avatar image RadhaUnity3d · Apr 24, 2013 at 07:37 AM 0
Share

i am geting this error : ArgumentException: You are not allowed to call INTERNAL_CALL_ScreenPointToRay when declaring a variable.

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

13 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

Related Questions

Multiple Cars not working 1 Answer

How To Invoke RayCastAll? 1 Answer

Line Renderer Collision Detection. 2 Answers

Why this script is not working? 1 Answer

hide object start script 4 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