I have a scene set up where I simply want to be able to select objects in a 3D scene and show the name of that object at the top of the screen. Not a problem. I can raycast to the object to identify it.
BUT, I also have a script which allows me to rotate the camera around by dragging your finger around the screen. The problem is, that my other script (that does the raycast, and shows the name of the ‘touched’ object) will keep detecting any object that are touched along the way.
I’d like the objects text to NOT show up when DRAGGED past. I’d only like the name to show up when TAPPED.
I’d guess check the distance between the finger down position and the finger up position, then decide whether or not to raycast at the finger up(to allow a slight bit of error).
Unity’s probably already got this covered, but you know me. Well, you don’t know me. I’m Joe. And I’m a bit ignorant.
Actually never mind that because for swipes, tapcount is always == 1.
Coincidentally i am working on the same problem for my game. A swipe will be “shuffle” and a single tap will be “pick”. The concept described in the Dev Center apply to Unity iPhone too, because the functions and structures for iPhoneTouch wrappers (or at least are analagous for CocoaTouch)
Dev Center says "By looking for the tap count in the touch-up phase (UITouchPhaseEnded), you ensure that the finger is really tapping and not, for instance, touching down and then dragging. "
for (var event : iPhoneTouch in iPhoneInput.touches)
{
if(event.phase == iPhoneTouchPhase.Ended)
{
if(event.tapCount == 1)
{
Debug.Log("Single Tap!");
}
}
mindlube - You the man! Works beautifully. I can now drag across the objects and NOT get them selected, but it still selects with a tap. Here is the code I used FYI:
static var currentObject:GameObject;
function Update()
{
var hit : RaycastHit;
for (var event : iPhoneTouch in iPhoneInput.touches)
{
if(event.phase == iPhoneTouchPhase.Ended)
{
if(event.tapCount == 1)
{
var ray = Camera.main.ScreenPointToRay (event.position);
if (Physics.Raycast (ray, hit, 500))
{
Debug.DrawLine (ray.origin, hit.point, Color.red);
currentObject = hit.collider.gameObject;
}
}
}
}
}
I tried to move an object with your script, but nothing happens, I tried to put the script in the main camera, in a cube , but nothing … you can give me some help?