• 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 Jannis501 · Nov 13, 2012 at 10:03 PM · raycastprefabs

When i click on Object, .. raycast help!

Hey,

I'm new in programming Java and speaking english, I'm from germany.. So I hava this problem:

I'm making a horror game and I want to create objects like a taclight, doors and other things.. But I want these objects to start the function "ClickOnObject" when clicking them.. i have a raycast, but i don't know how to do that, so please help me. It would be great when i could copy for example the doors, as many times as i want and everytime the clicked door opens, the taclight or paper or what else will do "ClickOnObject".. Is that possible? 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 Fattie · Nov 14, 2012 at 06:45 AM 0
Share

Your english is better than most english speakers!

there are some good examples right on teh doc page

Documentation/ScriptReference/Physics.Raycast.html
Documentation/ScriptReference/Collider.Raycast.html

massive discussion on detailed related issues ...

http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html

search on here for many many examples,

http://answers.unity3d.com/questions/23711/destroy-object-on-mouse-click.html

mfg !

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Nov 14, 2012 at 06:49 AM

this is in C# but its an example of a door in front of you being found and the player clicking.

Ray MyRay; RayCastHit HitInfo;

 //cast from the cameras postion
 MyRay.origin = Camera.main.transform.position;
 
 //cast directly out in front of the camera
 MyRay.direction = Camera.main.transform.forward;
 
 
 physics.raycast(Myray, out HitInfo);
 
 if (HitInfo)
 {
   if(HitInfo.gameobject.tag == "Door")
   {
     if(Input.GetMouseButtonDown(0))
      { 
        someone just clicked and a door is in front of you 
      }
    }
 }
Comment
Add comment · 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
0

Answer by Jannis501 · Nov 14, 2012 at 04:03 PM

Tank you, but i explain my problem

I have a door prefab ( "Door" ) with a object in it ( "Door_1") with a door object in it..

so when i click the "Door" i want "Door_1" to start the animation "Open"..

But just the door i clicked has to start the animation, you unsterand?

thanks

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Unity2d : Spawning in Prefabs 1 Answer

How to fill selected area with prefabs? 1 Answer

Logic problem with RaycastHit and prefabs scripts 0 Answers

Round Raycast Hit Point? 1 Answer

Activating only one of many prefabs with the same tag 1 Answer


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