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 Adam 2 · Jul 16, 2010 at 03:33 PM · javascriptdetectiononmouseover

Is there a way to detect from which GameObject OnMouseOver come from?

I have a monster, and i want to attach an OnMouseOver so its something like this : (QUICK MOCH UP)

function OnMouseOver(){
if(Input.GetKeyDown(KeyCode.Mouse0)){
//somehow figureout what clicked and send a message to that person saying attack monster
}
}

that way theperson will strt attacking him, so is there anyway to detect this?

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 equalsequals · Jul 16, 2010 at 04:09 PM 0
Share

Sorry, I think I understand what you are asking but I'm not sure so I'm going to confirm.

So are you creating some sort of drag mechanic?

ie I click on Hero1 and drag over to $$anonymous$$onster1, the On$$anonymous$$ouseOver is fired on $$anonymous$$onster1 and you want to know what hero was originally clicked??

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by matyicsapo · Jul 16, 2010 at 04:06 PM

You can query the mouse position from Input which is a screen position Check the Camera class for stuff like ScreenPointToRay() and try doing a raycast with the ray returned.

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 StephanK · Jul 16, 2010 at 04:17 PM

Maybe I misunderstood you, but per definition a MouseClick will always be performed by the user. A GameObject can't "click" on some other object... Also there is the OnMouseDown() method which will work for you in this case.

Comment
Add comment · Show 4 · 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 Adam 2 · Jul 17, 2010 at 07:30 AM 0
Share

this i all know, but my $$anonymous$$m and I ar adding network scripting soon. I dont know how it works at all, but I assume that if you have multiple gameObjects that are controled by people running around with the same name, then using GameObject.Find("Player"); isnt going to work. like in my head it says that if one person clicks on it, then the function will run for both players.

avatar image Adam 2 · Jul 17, 2010 at 07:31 AM 0
Share

also sorry if i type bad, my keyboard doesnt pick up some keystroks i hit

avatar image StephanK · Jul 17, 2010 at 10:38 AM 0
Share

You should have mentioned, that you are dealing with a network situation here... ;) You are right, if every player has a controller script attached you would move all instances at once. However you could just include some lines in your script to check if the player belongs to this computer or not and if not disable the Input functions. You can do this by checking if the Network.player belongs to you. Look up Network.player and NetworkPlayer in the scripting manual to see the details on that.

avatar image Adam 2 · Jul 17, 2010 at 05:28 PM 0
Share

alright, i also had an idea of using a raycast from the mouse, and everytime you click do something like Other.Send$$anonymous$$essageUpwards("Activat",gameObject); this way i can use this for shops, combat system, ect.

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

No one has followed this question yet.

Related Questions

How to detect a collision between two certain objects 0 Answers

Scripted UI.text not shows on duplicated object 0 Answers

Collision isn't detected between two obects 1 Answer

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

Touch Detection on Object in javascript 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