Basically, I have got game object selecting to work, like you click some object in-game and something happens, like an animation or something.
But what’s not right, is that for example if I make the player to perform an animation when he clicks on an in-game object, lets say table, what’s not right is that then the player could just stand on the other side somewhere far away from that table object, click on it and he would perform animation, and it’s just wrong
What I want to happen is, either:
-If player is far away from that object and click on it nothing would happen, he’d have to be close/ right next to the object and click again for the action to be performed.
or
-Basically what I just said above, but player would automatically walk to the object if he clicks it when far away and the action would perform after he walks to the object.
How could I make this work?
I have object selecting and all that working, only need to know how to add this distance stuff.
That will get you the distance to the object clicked. Now you can do what you like with it. For instance in my game I have a loot chest when an enemy dies. If the player clicks on the chest and is more a foot or so away I display the message “Too far to loot the chest”. You could either display a similar message OR you could get the clicked objects position (see code above) and then have the player move to it. If you are using CharacterController on the player use
the Move method on that object.
Could you maybe show your script you use for object selecyion?
I could really use that since I am working on almost the same thing, but I lack the right way to select the object I am clicking on. And then after he should move to the selected object like this thred is about.
Go ahead and put up the code that you are working on yourself. Oscar’s thread is old, and (knowing him) I’m sure he solved his problem months ago. He moves fast!
So put up your code or start a thread all your own and we can help you.
Basically, to be able to click on object you need object to have a collider of some kind. With a collider attached, you make a script with OnMouseOver, OnMouseEnter, OnMouseExit, as shown here: