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 /
This question was closed May 16, 2012 at 09:36 AM by Bunny83 for the following reason:

Problem is outdated

avatar image
0
Question by Gael51 · May 04, 2012 at 04:02 PM · gameobjectmouseclick

MouseClick and gameObject

Hi, I want to retrieve the name of this gameObject on my scene when I click on an object in order to execute an animation but I can not do it. My click return nothing.

Code :

// Builds a ray from camera point of view to the mouse position

     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit;
     // Casts the ray and get the first game object hit
     if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
         return hit.transform.gameObject;
     else
         return null;

Do you have an idea of the problem ? I attach this script on my gameObject (a Door)

Thanks

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 hijinxbassist · May 04, 2012 at 05:20 PM 0
Share

@Gael51 You can try using http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseUpAsButton>On$$anonymous$$ouseUpAsButton() if the door has a collider. Add that to the door, you will need the door to then pass the info from that function to wherever you need it

 function On$$anonymous$$ouseUpAsButton()
 {
     animation$$anonymous$$oderator.GetComponent($$anonymous$$yAnimations).PlayAnimation(this.gameObject);
 }

or however you are using the "hit" gameObject info.

avatar image dannyskim · May 04, 2012 at 06:26 PM 0
Share

are you sure you set up your layer mask properly? Did you assign's it's value manually by using a bit-wise statement, or did you make it a public variable and set the mask in the inspector?

avatar image Gael51 · May 16, 2012 at 09:22 AM 0
Share

Excuse me for being late but I solved my problem. $$anonymous$$y object was. Fbx that I mattered and properties was not correct

avatar image Bunny83 · May 16, 2012 at 09:35 AM 0
Share

So i guess there's no answer to this question...

I'm going to close it since it seems to be solved.

1 Reply

  • Sort: 
avatar image
0

Answer by Gael51 · May 09, 2012 at 08:43 AM

I simplified my code :

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

RaycastHit hit;

// Casts the ray and get the first game object hit

     if (Physics.Raycast(ray, out hit))
     {
         Debug.Log("This hit at " + hit.point );
         return hit.transform.gameObject;
     }
     else
     {
         Debug.Log("null");
         return null;        
     }

But nothing. The variable 'ray' is correctly implemented. I noticed that the variable returned a lightMapCoord NullException

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

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

selected object in array lost in translation 0 Answers

make object disappear after being thrown when mouse clicked anywhere ? 1 Answer

How to make when object is pressed, object2 does something? 0 Answers

Detect UI Panel click 2 Answers

Script for play audioclip on every object in the game by mouse click 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