Friday 15 August 2014

unityscript - unity3d move by touching -


I'm going to create an Android app where I'm transferring games, by touching objects on X and Z cord The object is to move right, left, top, or bottom I wrote this script which comes under a game object, where I check to touch the tip.

Do you know any other method for transferring the object?

  #pragma Strictly hit = new recurrence (); Function Start () {} Function Fixed Update () {for (var i: int = 0; i & lt; Input.touchCount; ++ i) {if (Input.GetTouch (0) .phase == TouchPhase.Moved) { Var TouchDilta Position: Vector 2 = Input Gettouch (i) .Deltation; Var touch_pos: vector 3 = new vector 3 (Input GateTouch (i) .bg.x, Input GateTouch (i). Position.y, 0); Var Re: Ray = Camera. ScreenPortire (touch_poz); Debug Drerey (Ray Orgin, Ray Direction * 10, Color. Yellow); If (phys.recorder (ray, hit)) (Debug.Log (hit.transform.tag); if (hit.transform.tag == "cubes") {if (Mathf.Abs (Input.GetTouch (i) DeltaPosition.x)> Mathf.Abs (Input.GetTouch (i) .deltaposition.y)) {if (Input GETTouch (i) .deltaPosition.x> 0) {transform.Translate (0,0, 1); // 'right';} and (conversion). Transcellate (0,0, -1); //GUItest.text = 'left';}} Else {if (Input.GetTouch (i) .deltaPosition Y> 0) {transform.Translate (-1,0,0); // 'above';} and {translated. Translated (1,0,0); // 'morning';}}}}} }   

}

Take touch status and store it Comparison of touch position to Delta And move the object

  if (Input.GetMouseButtonDown (0)) // // print ("up ..."); mousePositionXYZ.y = input. MousePosition.y; alarms True =;} if (doit) {listGO = GameObject.Find ("main camera"); If (Input.mousePosition.y> mousePositionXYZ.y) {listGO.transform.position.z - = Input Mouseposition.y * Time.deltaTime * 0.010; Print ("up ..."); } Else if (Input.mousePosition.y & lt; mousePositionXYZ.y) {listGO.transform.position.z + = Input Mouseposition.y * Time.deltaTime * 0.010; Print ("below ..."); }} If (Input. GetMouseButtonUp (0)) {mousePositionXYZ.y = Input.mousePosition.y; False = false; }    

No comments:

Post a Comment