private void GotoThePlayer() { float distanceToAchieve = Mathf.SmoothStep(distanceToPlayer, targetDistance, timer / timeToArriveAndScape); Vector2 newPosition = GetPointDistanceFromObject(distanceToAchieve, (transform.position - playerParentTransform.position).normalized); transform.position = newPosition; if (distanceToAchieve == targetDistance) { if (status == Statuses.GettingClose) { status = Statuses.Shooting; _shooter.FromCurrentShootingState(false, false, false, gameObject, Time.deltaTime, 1, 0f); timer = 0; } } }
void Update() { var escape = KeyCode.Escape; var up = KeyCode.UpArrow; var down = KeyCode.DownArrow; var left = KeyCode.LeftArrow; var right = KeyCode.RightArrow; var space = KeyCode.Space; var control = KeyCode.LeftControl; var wKey = KeyCode.W; var aKey = KeyCode.A; var sKey = KeyCode.S; var dKey = KeyCode.D; timerLazer += Time.deltaTime; if (Input.GetKeyDown(escape) && Time.timeScale == 1 && !bestScoreMenu.activeSelf) { Time.timeScale = 0; pauseMenu.SetActive(true); Camera.main.GetComponent <MusicManager>().PauseMusic(); } else if (Input.GetKeyDown(escape) && Time.timeScale == 0 && !bestScoreMenu.activeSelf) { pauseMenu.SetActive(false); Time.timeScale = 1; Camera.main.GetComponent <MusicManager>().ResumeMusic(); } if (Input.GetKey(up) || Input.GetKey(wKey)) { movementX = -1; } else if (Input.GetKey(down) || Input.GetKey(sKey)) { movementX = 1; } else { movementX = 0; } if (Input.GetKey(left) || Input.GetKey(aKey)) { movementY = -1; } else if (Input.GetKey(right) || Input.GetKey(dKey)) { movementY = 1; } else { movementY = 0; } var screenPos = _mainCamera.WorldToScreenPoint(transform.position); // Pressing Right creates movement in the positive Y coordinates... makes these conditions a bit weird, fix it somehow if it becomes too annoying if (screenPos.x - _halfSpriteRect.width < 0 && movementY < 0) { movementY = 0; } else if (screenPos.x + _halfSpriteRect.width > _mainCamera.pixelWidth && movementY > 0) { movementY = 0; } if (screenPos.y - _halfSpriteRect.height < 0 && movementX > 0) { movementX = 0; } else if (screenPos.y + _halfSpriteRect.height > _mainCamera.pixelHeight && movementX < 0) { movementX = 0; } if (characterEnabled) { //Animation if (movementX > 0) { anim.SetBool("GoingRight", true); } else { anim.SetBool("GoingRight", false); } if (movementX < 0) { anim.SetBool("GoingLeft", true); } else { anim.SetBool("GoingLeft", false); } if (timerLazer < lazerDuration) { currentSpeed = MovementSpeed / 3; Physics2D.IgnoreLayerCollision(gameObject.layer, LayerMask.NameToLayer("EnemyLayer"), true); } else { Physics2D.IgnoreLayerCollision(gameObject.layer, LayerMask.NameToLayer("EnemyLayer"), false); currentSpeed = MovementSpeed; //Primary attack _activeShooter.FromCurrentShootingState(Input.GetKeyDown(space) || Input.GetMouseButtonDown(0), Input.GetKeyUp(space) || Input.GetMouseButtonUp(0), Input.GetKey(space) || Input.GetMouseButton(0), gameObject, Time.deltaTime, gunLevel, 2f, 1 + damageLevel * 0.5f); //secondary attack if ((Input.GetKeyDown(control) || Input.GetMouseButtonDown(1)) && laserQuantity > 0) { timerLazer = 0; laserQuantity--; UpdatePowerupUI(); GetShooterOfType <BlastShooter>().FromCurrentShootingState(Input.GetKeyDown(control) || Input.GetMouseButtonDown(1), Input.GetKeyUp(control) || Input.GetMouseButtonUp(1), Input.GetKey(control) || Input.GetMouseButton(1), gameObject, Time.deltaTime, laserQuantity, lazerDuration); } } } }