- Home /
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?
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??
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.
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.
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.
also sorry if i type bad, my keyboard doesnt pick up some keystroks i hit
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.
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.