private IEnumerator SavingPlayer() { savePlayerCountDown.StartToCount(); while (true) { if (Input.GetKey(KeyCode.J)) { CountDown.DecreaseTime(savePlayerCountDown); yield return(new WaitForSeconds(Time.deltaTime)); } else { print("não salvou!"); savePlayerCountDown.CoolDown = 0; break; } if (savePlayerCountDown.ReturnedToZero) { print("salvou!"); model.IsDead = false; model.CurrentLife = 3; DAL.ProjectVikingsContext.alivePlayers.Add(model.GameObject); GetComponents <BoxCollider2D>().Where(x => !x.isTrigger).ToList().ForEach(x => x.enabled = true); LifeBar.value = CalculateLife(); if (model.IsTank) { DAL.ProjectVikingsContext.alivePrefPlayers.Add(model.GameObject); } PlayerAnimator.SetBool("WasSafe", true); break; } } SetForceToStop(false); }
void Update() { boxColliderBoundMin = BoxCollider2D.bounds.min; CountDown.DecreaseTime(destroyCountDown); if (destroyCountDown.ReturnedToZero) { Destroy(gameObject); } if (!stop) { if (Vector3.Distance(new Vector2(transform.position.x, transform.position.y), new Vector2(startPosition.x, startPosition.y)) < distance * holdTime) { Animator.SetBool("Fly", true); transform.position = Vector3.MoveTowards(transform.position, transform.position + direction * (2 * holdTime), 4); } else { Stop(); } Collider(); } transform.position = Utils.SetPositionZ(transform, BoxCollider2D.bounds.min.y); }
private void FixedUpdate() { if (disabledCountDown.CoolDown > 0) { CountDown.DecreaseTime(disabledCountDown); return; } if (model.IsDead) { return; } EnemyUpdate(); if (enemyController.fow.visibleTargets.Count > 0) { enemyController.FindTarget(transform); if (enemyController.target != null) { if (Vector2.Distance(transform.position, enemyController.target.position) > 0.5f) { enemyController.WalkTowardTo(transform, ref model); EnemyAnimator.SetBool("isWalking", true); } else { enemyController.canAttack = true; } } else { EnemyAnimator.SetBool("isWalking", false); } } else { EnemyAnimator.SetBool("isWalking", false); enemyController.target = null; enemyController.canAttack = false; } if (attackCountDown.CoolDown > 0 && enemyController.canAttack) { enemyController.Attack(transform, BoxCollider2D.size, playerLayer); } if (attackCountDown.CoolDown <= 0) { enemyController.targetsAttacked.Clear(); if (enemyController.canAttack) { attackCountDown.StartToCount(); } } }
void Update() { CountDown.DecreaseTime(animatorCount); if (animatorCount.ReturnedToZero) { Animator.SetBool("Collided", false); } transform.position = Utils.SetPositionZ(transform, BoxCollider2D.bounds.min.y); }
public void EnemyUpdate() { CountDown.DecreaseTime(enemyController.followPlayer); CountDown.DecreaseTime(attackCountDown); var input = enemyController.GetInput(); EnemySpriteRenderer.flipX = input.Flip.Value; EnemyAnimator.SetFloat("speedX", input.Vector2.x); EnemyAnimator.SetFloat("speedY", input.Vector2.y); }
private void Update() { if (timeCount.CoolDown > 0) { CountDown.DecreaseTime(timeCount); } else if (timeCount.CoolDown < 0) { timeCount.CoolDown = 0; } timeText.text = timeCount.CoolDown.ToString().Replace('.', ':'); }
private void Update() { if (direction? transform.position.x <= Camera.main.transform.position.x : transform.position.x >= Camera.main.transform.position.x) { if (direction? transform.position.x + cameraPosition + 0.67786f <= Camera.main.transform.position.x : transform.position.x - cameraPosition - 0.67786f >= Camera.main.transform.position.x) { isActivated = false; } else { isActivated = true; } } else { isActivated = false; } if (isActivated) { CountDown.DecreaseTime(countDownEffect); if (countDownEffect.ReturnedToZero) { countDown.Rate = timeToRespaw; countDown.StartToCount(); } CountDown.DecreaseTime(countDown); if (countDown.ReturnedToZero) { countDown.StartToCount(); var fireBall = Instantiate(prefabFireBall, transform.position + new Vector3(0.421f, -0.373f, 0), Quaternion.identity); fireBall.GetComponent <MoveObjects>().direction = direction; if (!direction) { fireBall.GetComponents <Transform>().ToList().ForEach(x => x.localScale = -x.localScale); fireBall.GetComponentsInChildren <Transform>().ToList().ForEach(x => x.localScale = -x.localScale); } sr.sprite = secondFrame; Invoke("FramesInteraction", 1); } } }
private void FixedUpdate() { PlayerSpriteRenderer.material.SetFloat("_BottomLimit", transform.position.y - halfSizeY + distanceCenterWater); if (disabledCountDown.CoolDown > 0) { CountDown.DecreaseTime(disabledCountDown); return; } if (model.IsDead) { return; } CharacterUpdate(); CountDown.DecreaseTime(attackCountDown); if (isPlayable) { #region Attack if (attackCountDown.CoolDown <= 0) { playerController.targetsAttacked.Clear(); if (attackCountDown.ReturnedToZero) { model.SpeedRun = model.SpeedWalk * 2; model.SpeedWalk = model.SpeedWalk * 2; } if (Input.GetKey(KeyCode.L)) { playerController.AttackMode(); model.SpeedRun = model.SpeedWalk / 2; model.SpeedWalk = model.SpeedWalk / 2; attackCountDown.StartToCount(); } } else { playerController.Attack(transform, PlayerCollider2D.size); } #endregion if (Input.GetKey(KeyCode.P)) { playerController.Defend(ref model); } if (Input.GetKeyUp(KeyCode.P)) { model.DirectionsDefended = null; } } else { #region Attack if (model.PlayerMode == PlayerModes.Attack) { if (playerController.fow.visibleTargets.Count > 0) { playerController.FindTarget(transform); if (playerController.target != null) { if (Mathf.Abs(Vector3.Distance(transform.position, playerController.target.position)) > 0.5) { playerController.WalkTowardTo(transform, ref model); PlayerAnimator.SetBool("isWalking", true); } else { playerController.canAttack = true; } } else { PlayerAnimator.SetBool("isWalking", false); } } else { if (Mathf.Abs(Vector3.Distance(transform.position, cv.playerGameObj.transform.position)) > DistanceOfPlayer) { playerController.WalkToPlayer(transform, cv.playerGameObj.transform, ref model); PlayerAnimator.SetBool("isWalking", true); } else { PlayerAnimator.SetBool("isWalking", false); PlayerAnimator.SetBool("isRunning", false); } input = playerController.GetInput(model.LastMoviment.Value); PlayerSpriteRenderer.flipX = input.Flip.Value; PlayerAnimator.SetFloat("speedX", input.Vector2.x); PlayerAnimator.SetFloat("speedY", input.Vector2.y); playerController.target = null; playerController.canAttack = false; } } if (attackCountDown.CoolDown <= 0) { playerController.targetsAttacked.Clear(); if (attackCountDown.ReturnedToZero) { model.SpeedRun = model.SpeedRun * 2; model.SpeedWalk = model.SpeedWalk * 2; } if (playerController.canAttack) { model.SpeedRun = model.SpeedRun / 2; model.SpeedWalk = model.SpeedWalk / 2; attackCountDown.StartToCount(); } } else if (playerController.canAttack && playerController.target != null) { playerController.Attack(transform, PlayerCollider2D.size); } #endregion } }
private void FixedUpdate() { if (oldTarget != playerController.target) { YRange = startYRange; XRange = startXRange; } oldTarget = playerController.target; CharacterUpdate(); CountDown.DecreaseTime(attackCountDown); if (isPlayable) { if (Input.GetKey(KeyCode.Mouse0)) { mouseIn = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); Counter.Count(counter); } if (Input.GetKeyUp(KeyCode.Mouse0)) { var vectorDirection = mouseIn - new Vector2(transform.position.x, transform.position.y); var degrees = (Mathf.Atan2(vectorDirection.y, vectorDirection.x) * Mathf.Rad2Deg) - 90; if (degrees < 0f) { degrees += 360f; } var arrow = Instantiate(Arrow, new Vector3(transform.position.x, transform.position.y, -80), Quaternion.Euler(0, 0, degrees)); var script = arrow.GetComponent <ArrowView>(); script.mouseIn = mouseIn; script.holdTime = counter.Time; counter.ResetCounter(); playerController.AttackMode(); } } else { if (model.PlayerMode == PlayerModes.Attack) { if (playerController.fow.visibleTargets.Count > 0) { playerController.FindTarget(transform); if (playerController.target != null) { playerController.canAttack = true; } } else { if (Mathf.Abs(Vector3.Distance(transform.position, cv.playerGameObj.transform.position)) > DistanceOfPlayer) { playerController.WalkToPlayer(transform, cv.playerGameObj.transform, ref model); PlayerAnimator.SetBool("isWalking", true); } else { PlayerAnimator.SetBool("isWalking", false); PlayerAnimator.SetBool("isRunning", false); } input = playerController.GetInput(); PlayerSpriteRenderer.flipX = input.Flip.Value; PlayerAnimator.SetFloat("speedX", input.Vector2.x); PlayerAnimator.SetFloat("speedY", input.Vector2.y); playerController.target = null; playerController.canAttack = false; } } if (attackCountDown.CoolDown <= 0) { playerController.targetsAttacked.Clear(); if (attackCountDown.ReturnedToZero) { model.SpeedRun = model.SpeedRun * 2; model.SpeedWalk = model.SpeedWalk * 2; } if (playerController.canAttack) { model.SpeedRun = model.SpeedRun / 2; model.SpeedWalk = model.SpeedWalk / 2; attackCountDown.StartToCount(); if (playerController.target != null) { Shoot(); } playerController.canAttack = false; } } } }
private void FixedUpdate() { PlayerSpriteRenderer.material.SetFloat("_BottomLimit", transform.position.y - halfSizeY + distanceCenterWater); if (disabledCountDown.CoolDown > 0) { CountDown.DecreaseTime(disabledCountDown); return; } if (model.IsDead) { return; } if (_oldTarget != playerController.target) { YRange = startYRange; XRange = startXRange; } _oldTarget = playerController.target; CharacterUpdate(); CountDown.DecreaseTime(attackCountDown); if (isPlayable) { if (attackCountDown.CoolDown <= 0) { if (Input.GetKey(KeyCode.Mouse0)) { if (!hadVelocityDecrease) { model.SpeedRun = model.SpeedRun / 2; model.SpeedWalk = model.SpeedWalk / 2; hadVelocityDecrease = true; } Counter.Count(counter); } if (Input.GetKeyUp(KeyCode.Mouse0)) { mouseIn = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); Shoot(counter.Time, true); counter.ResetCounter(); playerController.AttackMode(); model.SpeedRun = model.SpeedRun * 2; model.SpeedWalk = model.SpeedWalk * 2; attackCountDown.StartToCount(); hadVelocityDecrease = false; } } } else { if (attackCountDown.ReturnedToZero) { model.SpeedRun = model.SpeedRun * 2; model.SpeedWalk = model.SpeedWalk * 2; } if (model.PlayerMode == PlayerModes.Attack) { if (playerController.fow.visibleTargets.Count > 0) { playerController.FindTarget(transform); if (playerController.target != null) { playerController.canAttack = true; } } else { if (Mathf.Abs(Vector3.Distance(transform.position, cv.playerGameObj.transform.position)) > DistanceOfPlayer) { playerController.WalkToPlayer(transform, cv.playerGameObj.transform, ref model); PlayerAnimator.SetBool("isWalking", true); } else { PlayerAnimator.SetBool("isWalking", false); PlayerAnimator.SetBool("isRunning", false); } input = playerController.GetInput(model.LastMoviment.Value); PlayerSpriteRenderer.flipX = input.Flip.Value; PlayerAnimator.SetFloat("speedX", input.Vector2.x); PlayerAnimator.SetFloat("speedY", input.Vector2.y); playerController.target = null; playerController.canAttack = false; } } if (attackCountDown.CoolDown <= 0) { playerController.targetsAttacked.Clear(); if (playerController.canAttack && playerController.target != null) { model.SpeedRun = model.SpeedRun / 2; model.SpeedWalk = model.SpeedWalk / 2; attackCountDown.StartToCount(); var randomX = UnityEngine.Random.Range(XRange.x, XRange.y); var randomY = UnityEngine.Random.Range(YRange.x, YRange.y); SetMinManRange(randomX, "X"); SetMinManRange(randomY, "Y"); mouseIn = new Vector2(playerController.target.position.x + randomX, playerController.target.position.y + randomY); Shoot(1); playerController.canAttack = false; } } } }
public void CharacterUpdate() { CountDown.DecreaseTime(changeCharacterCountDown); CountDown.DecreaseTime(playerController.followEnemy); var tempIsControllable = playerController.GetIsControllable(); if (isPlayable != tempIsControllable) { changeCharacterCountDown.StartToCount(); } if (isPlayable != tempIsControllable) { SetSlideSizes(); } isPlayable = tempIsControllable; if (isPlayable) { if (playerController.target != oldTarget) { oldTarget = playerController.target; if (playerController.target != null) { PlayerController.GetSliderEnemy(playerController.target); } } #region Mover if (!model.ForceToStop) { input.Vector2 = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); foreach (var keyMove in utils.moveKeyCode) { if (Input.GetKey(keyMove.KeyCode.Value)) { if (Input.GetKey(KeyCode.LeftShift) && !model.ForceToWalk) { PlayerAnimator.SetBool("isRunning", true); PlayerAnimator.SetBool("isWalking", false); playerController.Walk(keyMove.Vector2, (float)model.SpeedRun); } else { PlayerAnimator.SetBool("isWalking", true); PlayerAnimator.SetBool("isRunning", false); playerController.Walk(keyMove.Vector2, (float)model.SpeedWalk); } playerController.SetLastMoviment(input.Vector2.x, input.Vector2.y); PlayerAnimator.SetFloat("speedX", input.Vector2.x); PlayerAnimator.SetFloat("speedY", input.Vector2.y); if (!keyMove.Flip.HasValue) { continue; } PlayerSpriteRenderer.flipX = keyMove.Flip.Value; } if (Input.GetKeyUp(keyMove.KeyCode.Value)) { PlayerAnimator.SetBool("isWalking", false); PlayerAnimator.SetBool("isRunning", false); } } } if (model.ForceToStop) { PlayerAnimator.SetBool("isWalking", false); PlayerAnimator.SetBool("isRunning", false); } #endregion #region Change Character if (changeCharacterCountDown.CoolDown <= 0 && Input.GetKeyDown(KeyCode.K) && !model.ForceToStop) { playerController.ChangeControllableCharacter(); camera.SendMessage("UpdatePlayerTranform"); SetSlideSizes(); } #endregion #region Interact if (Input.GetKey(KeyCode.J)) { playerController.Interact(transform, PlayerCollider2D.size); } #endregion } else { #region Follow if (model.PlayerMode == PlayerModes.Follow) { if (Mathf.Abs(Vector3.Distance(transform.position, cv.playerGameObj.transform.position)) > DistanceOfPlayer) { //playerController.WalkToPlayer(transform, cv.playerGameObj.transform, ref model); playerController.target = cv.playerGameObj.transform; Move(); PlayerAnimator.SetBool("isWalking", true); } else { PlayerAnimator.SetBool("isWalking", false); PlayerAnimator.SetBool("isRunning", false); } } #endregion #region Walk Input input = playerController.GetInput(model.LastMoviment.Value); PlayerSpriteRenderer.flipX = input.Flip.Value; PlayerAnimator.SetFloat("speedX", input.Vector2.x); PlayerAnimator.SetFloat("speedY", input.Vector2.y); #endregion if (Vector3.Distance(transform.position, cv.playerGameObj.transform.position) > 15) { model.PlayerMode = PlayerModes.Follow; } } transform.position = Utils.SetPositionZ(transform, colliderTransform.bounds.min.y); #region Change PlayerMode foreach (var playerMode in utils.playerModes) { if (Input.GetKey(playerMode.KeyButton[0]) && Input.GetKey(playerMode.KeyButton[1])) { model.PlayerMode = playerMode.Value; if (playerMode.Value == PlayerModes.Wait) { PlayerAnimator.SetBool("isWalking", false); PlayerAnimator.SetBool("isRunning", false); } } } #endregion }
private void FixedUpdate() { if (disabledCountDown.CoolDown > 0) { CountDown.DecreaseTime(disabledCountDown); return; } if (model.IsDead) { return; } if (oldTarget != enemyController.target) { YRange = startYRange; XRange = startXRange; } if (enemyController.target != null) { oldTarget = enemyController.target; } EnemyUpdate(); if (enemyController.fow.visibleTargets.Count > 0) { enemyController.FindTarget(transform); if (enemyController.target != null) { if (Vector2.Distance(transform.position, enemyController.target.position) > 4) { enemyController.WalkTowardTo(transform, ref model); EnemyAnimator.SetBool("isWalking", true); } else { enemyController.canAttack = true; EnemyAnimator.SetBool("isWalking", false); } } else { EnemyAnimator.SetBool("isWalking", false); } } else { EnemyAnimator.SetBool("isWalking", false); enemyController.target = null; enemyController.canAttack = false; } if (attackCountDown.CoolDown <= 0) { enemyController.targetsAttacked.Clear(); if (attackCountDown.ReturnedToZero) { model.SpeedRun = model.SpeedRun * 2; model.SpeedWalk = model.SpeedWalk * 2; } if (enemyController.canAttack) { model.SpeedRun = model.SpeedRun / 2; model.SpeedWalk = model.SpeedWalk / 2; attackCountDown.StartToCount(); if (enemyController.target != null) { Shoot(); } enemyController.canAttack = false; } } }