Entradas

Mostrando las entradas de agosto, 2020

Pixel To World Unit Conversion

  using   UnityEngine ; using   System.Collections ;   public   class  ResolutionCompensation  :  MonoBehavior { public  Vector2 WorldUnitsInCamera ; public  Vector2 WorldToPixelAmount ;   public  GameObject Camera ;   void  Awake  ( ) {          //Finding Pixel To World Unit Conversion Based On Orthographic Size Of Camera         WorldUnitsInCamera . y   =  Camera . GetComponent < Camera > ( ) . orthographicSize   *   2 ;         WorldUnitsInCamera . x   =  WorldUnitsInCamera . y   *  Screen . width   /  Screen . height ;           WorldToPixelAmount . x   =  Screen . width   /  WorldUnitsInCamera . x ;         WorldToPixelAmount . y   =  Screen . height   /  WorldUnitsInCamera . y ; }     //Taking Your Camera Location And Is Off Setting For Position And For Amount Of World Units In Camera public  Vector2 ConvertToWorldUnits ( Vector2 TouchLocation ) {       Vector2 returnVec2 ;   returnVec2 . x   =   ( ( TouchLocation . x   /  WorldToPixelAmount . x )   -   ( WorldUnitsInCamera

SWIPE IN UNITY

  void Update () { //Example usage in Update. Note how I use Input.GetMouseButton instead of Input.touch //GetMouseButtonDown(0) instead of TouchPhase.Began if (Input.GetMouseButtonDown(0)) { fingerStart = Input.mousePosition; fingerEnd = Input.mousePosition; } //GetMouseButton instead of TouchPhase.Moved //This returns true if the LMB is held down in standalone OR //there is a single finger touch on a mobile device if(Input.GetMouseButton(0)) { fingerEnd = Input.mousePosition; //There was some movement! The tolerance variable is to detect some useful movement //i.e. an actual swipe rather than some jitter. This is the same as the value of 80 //you used in your original code. if(Mathf.Abs(fingerEnd.x - fingerStart.x) > tolerance || Mathf.Abs(fingerEnd.y - fingerStart.y) > tolerance) { //There is more movement on the X axis than the Y axis if(Mathf.Abs(