void GenerateSymbol() { int spawningPoint_Index = UnityEngine.Random.Range(0, level.spawningPoints.Length); //Ojo, primero inclusivo y segundo exclusivo RectTransform spawningPoint = level.spawningPoints[spawningPoint_Index].transform; Vector2 direction = level.spawningPoints[spawningPoint_Index].Direction; float symbolSpeed = UnityEngine.Random.Range(level.symbolMinSpeed, level.symbolMaxSpeed + 1); SymbolMovement symbolMov = level.symbolMov; // Instantiate SymbolMovement newSymbolMov; newSymbolMov = Instantiate(symbolMov, spawningPoint.localPosition, transform.rotation) as SymbolMovement; // Si encuentro una forma mejor de hacerlo, lo haré... Spaguetti intensifies! newSymbolMov.GetComponent <Rigidbody2D>().velocity = transform.TransformDirection(direction * symbolSpeed); // Asigno la velocidad lineal (De momento fija, pero haremos un random ahora) newSymbolMov.Symbol = AllGestures.GetRandomSymbol(); //Se le asigna uno de los símbolos disponibles aleatoriamente (la imagen se asigna sola) newSymbolMov.transform.SetParent(this.transform, false); }
void OneTouchGestures () { if (Input.GetTouch(0).phase == TouchPhase.Began) { touchStartPoint = Input.GetTouch(0).position; // SD //allBetweenCombined += timeBetweenTouch; //avarageBetweenTime = allBetweenCombined / timesSwiped; } if (touchTime > tapTime && Input.GetTouch(0).phase == TouchPhase.Stationary && swipeDist < 50f) { currentGesture = AllGestures.TapHold; print("TapHold SwipeDist: " + swipeDist); } if (Input.GetTouch(0).phase == TouchPhase.Ended) { // SD /* timesSwiped++; allSwipeTimeCombined += touchTime; avarageTime = allSwipeTimeCombined / timesSwiped; if (minTime > touchTime) { minTime = touchTime; } if (maxTime < touchTime) { maxTime = touchTime; } */ if (touchTime < tapTime) { currentGesture = AllGestures.SingleTap; } // -- if (swipeDist > swipeDeadZone) { if (swipeDir.x > 0 && (swipeDir.x > swipeDir.y && swipeDir.x > swipeDir.y * -1)) { currentGesture = AllGestures.SwipeRight; swipeDir = Vector2.zero; } if (swipeDir.x < 0 && (swipeDir.x < swipeDir.y && swipeDir.x < swipeDir.y * -1)) { currentGesture = AllGestures.SwipeLeft; swipeDir = Vector2.zero; } if (swipeDir.y > 0 && (swipeDir.y > swipeDir.x && swipeDir.y > swipeDir.x * -1)) { currentGesture = AllGestures.SwipeUp; swipeDir = Vector2.zero; } if (swipeDir.y < 0 && (swipeDir.y < swipeDir.x && swipeDir.y < swipeDir.x * -1)) { currentGesture = AllGestures.SwipeDown; swipeDir = Vector2.zero; } print(currentGesture + " Swipe Dist: " + swipeDist); } gestureUsed = true; lastGesture = currentGesture; // SD //timeBetweenTouch = 0; } // -- touchLastPoint = Input.GetTouch(0).position; swipeDir = (touchLastPoint - touchStartPoint).normalized; swipeDist = (touchLastPoint - touchStartPoint).magnitude; }
void TwoTouchGestures () { touchOnePos = Input.GetTouch(0).position; touchTwoPos = Input.GetTouch(1).position; float currentDist = (touchOnePos - touchTwoPos).magnitude; if (Input.GetTouch(0).phase != TouchPhase.Stationary || Input.GetTouch(1).phase != TouchPhase.Stationary) { if (currentDist > twoTouchLastDist) { currentGesture = AllGestures.PinchOut; } else { currentGesture = AllGestures.PinchIn; } } if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(1).phase == TouchPhase.Ended) { gestureUsed = true; lastGesture = currentGesture; } twoTouchLastDist = (touchOnePos - touchTwoPos).magnitude; }