OnMouseDown

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(added iPhone category)
Line 1: Line 1:
 
[[Category:iPhone]]
 
[[Category:iPhone]]
  
This Javascript sends OnMouseDown messages based on iPhone taps, so you can use OnMouseDown callbacks. Attach the script to the camera that is rendering the clickable (tappable) objects. Add a layer argument to the Raycast call if you need to avoid unnecessary intersections. A similar script can be implemented for OnMouseUp (an exercise for the reader)
+
This Javascript sends OnMouseDown messages based on iPhone taps, so you can use OnMouseDown callbacks. Attach the script to the camera that is rendering the clickable (tappable) objects. Add a layer argument to the Raycast call if you need to avoid unnecessary intersections. A similar script can be implemented for OnMouseUp (an exercise for the reader). This is only for 3D objects with colliders (e.g. this is used for the 3D menus in HyperBowl), not for GUIText and GUITexture.
  
 
<javascript>
 
<javascript>

Revision as of 07:43, 19 July 2010


This Javascript sends OnMouseDown messages based on iPhone taps, so you can use OnMouseDown callbacks. Attach the script to the camera that is rendering the clickable (tappable) objects. Add a layer argument to the Raycast call if you need to avoid unnecessary intersections. A similar script can be implemented for OnMouseUp (an exercise for the reader). This is only for 3D objects with colliders (e.g. this is used for the 3D menus in HyperBowl), not for GUIText and GUITexture.

<javascript> function Update () {

  var hit : RaycastHit;
  for (var i = 0; i < iPhoneInput.touchCount; ++i) {
     if (iPhoneInput.GetTouch(i).phase == iPhoneTouchPhase.Began) {
     // Construct a ray from the current touch coordinates
     var ray = camera.ScreenPointToRay (iPhoneInput.GetTouch(i).position);
     if (Physics.Raycast (ray,hit)) {
        hit.transform.gameObject.SendMessage("OnMouseDown");
     }
  }
  }

} </javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox