|
Having trouble with this, and can't find a working example. I have 5 objects, that need to detect when they are tapped, this code seems to detect the taps if I place it on the objects, but picks up the tap anywhere on the screen, at the same time for all 5 objects! Any clues on how to just detect if the tap is on one object? The 3D objects have rigidbodies and colliders.
(comments are locked)
|
|
You can add another set of conditionals to check if the hit object is the one you want. By the way do not add this script to the objects, add it to an empty game object. Each instance of this script sends a new ray so with one tap you are sending a lot of rays for that frame right now.
(comments are locked)
|
|
Here is a clean way to get touch events on individual Game Objects without any switch. (my example use C#). The way I used is to create a script managing the Update(), getting which object is touched, and calling the MonoBehaviour script from the object itself. As I use Input component from Unity, it works on Desktop and iOS. The example use a sprite from 2DToolkit but can be applied to any GameObject type I believe... 1) Create an empty GameObject 2) Create a script called touchableManager and attach it to the empty game object. Here is the script: 3) Create a script called touchableGameobject, here is the code: 4) Attach this script to all your game objects!
(comments are locked)
|
|
heres the final code for those interested. Would still be interested in a bit of code that could be applied to individual objects though, tried out some other things, made sense in code but didn't work. Anyhow: this only works when the user lifts up their digit, sausage, whatever, without leaving the confines of that objects area, if they change their mind and slide their tap away, it reports the tap as cancelled. Doesn't work, It says that the array index is out of range.
Feb 06 '12 at 01:40 PM
MithosAnnar
(comments are locked)
|
|
Sure, create a new script named InputManager and fill it out as below. Then create a new Empty Game Object and name it InputManager just so you can find it later on in your scene and add this script to this GameObject. BTW I haven't tested this so my apologies if there are any typos or syntax errors.
(comments are locked)
|
|
well I finally got it working, here is my final script (badly commented) I hope people can use it. it is attached to a empty game object somewhere in the scene Dennis
(comments are locked)
|
1 2 next page »
