protected virtual void ControlFishy() { #if UNITY_WEBGL if (Input.GetKey(KeyCode.W) && transform.position.y < yBounds.y) { float delta = baseSpeeds.y * scrollManager.GetSpeedPercentage(); yVel = Mathf.Min(CalculateYVel(yVel, delta), maxSpeeds.y); } if (Input.GetKey(KeyCode.S) && transform.position.y > yBounds.x) { float delta = -baseSpeeds.y * scrollManager.GetSpeedPercentage(); yVel = Mathf.Max(CalculateYVel(yVel, delta), -maxSpeeds.y); } if (Input.GetKey(KeyCode.A)) { xVel = Mathf.Min(xVel + baseSpeeds.x, maxSpeeds.x); } if (Input.GetKey(KeyCode.D)) { xVel = Mathf.Max(xVel - baseSpeeds.x, -maxSpeeds.x); } #endif #if UNITY_ANDROID List <Touch> touches = InputHelper.GetTouches(); if (touches.Count > 0) { Vector3 touchWorldPosition = mainCamera.ScreenToWorldPoint(touches[0].position); touchWorldPosition.z = transform.position.z; float distanceToTouch = Mathf.Abs(touchWorldPosition.y - transform.position.y); // up and down float yVelDelta = touches[0].deltaPosition.y / 20f * scrollManager.GetSpeedPercentage(); //if out out bounds, don't let fishy move more out of bounds if (aboveBound) { yVelDelta = Mathf.Min(0, yVelDelta); } if (belowBound) { yVelDelta = Mathf.Max(0, yVelDelta); } yVel = CalculateYVel(yVel, yVelDelta); //// left and right //if (touches[0].phase == TouchPhase.Began) // firstTouchPosition = touchWorldPosition; //else //{ // float xVelScale = Mathf.Clamp(firstTouchPosition.x - touchWorldPosition.x, -touchDistanceThreshold, touchDistanceThreshold); // xVel = Mathf.Clamp(maxSpeeds.x * (xVelScale / touchDistanceThreshold), -maxSpeeds.x, maxSpeeds.x); //} } #endif }
void Awake() { startSpeedPercentage = scrollManager.GetSpeedPercentage(); bounds.center = transform.position; poolManager = FindObjectOfType <PoolManager>(); prefabPool = poolManager.AddPool(objectToEmit); }
private void Start() { xRange = maxX - minX; startSpeedPercentage = scrollManager.GetSpeedPercentage(); }