// Update is called once per frame void FixedUpdate() { if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (MouseData.tempItemBeingDragged == null && !EventSystem.current.IsPointerOverGameObject()) { if (Physics.Raycast(ray, out hit, 100)) { bool getEnemy = hit.collider.CompareTag("Enemy"); float distance = Vector3.Distance(transform.position, hit.point); if (getEnemy) { if (distance <= attackRange) { navMeshAgent.SetDestination(transform.position); LookatSlerp(hit); anim.SetBool("isShooting", true); //Debug.Log("attack"); shooting.Shoot(int.Parse(atkText.text)); } else { navMeshAgent.SetDestination(Vector3.MoveTowards(this.transform.position, hit.point, distance - attackRange)); LookatSlerp(hit); isMoveAndShoot = true; } } else { // Debug.Log("is running TRUE"); anim.SetBool("isShooting", false); anim.SetBool("isRunning", true); navMeshAgent.SetDestination(hit.point); } } } } else if (navMeshAgent.hasPath) { anim.SetBool("isShooting", false); anim.SetBool("isRunning", true); } else if (isMoveAndShoot) { anim.SetBool("isShooting", true); anim.SetBool("isRunning", false); shooting.Shoot(int.Parse(atkText.text)); isMoveAndShoot = false; } else { anim.SetBool("isShooting", false); anim.SetBool("isRunning", false); } }
private void FixedUpdate() { //===================PLAYER MOVEMENT=================== Vector2 desiredVelocity = movement * moveSpeed; rb.velocity = Vector2.SmoothDamp(rb.velocity, desiredVelocity, ref velocity, moveSmooth); Position = rb.position; //===================ROTATION WITH MOUSE=================== //Vector2 facingDirection = mousePosition - rb.position //float angle = Mathf.Atan2(facingDirection.y, facingDirection.x) * Mathf.Rad2Deg - 90f; //rb.rotation = angle; var x = joystick2.Horizontal; var y = joystick2.Vertical; if (x != 0.0 || y != 0.0) { float angle = Mathf.Atan2(y, x) * Mathf.Rad2Deg - 90f; //transform.rotation = Quaternion.AngleAxis(90.0f - angle, Vector3.up); rb.rotation = angle; //float nextTimeToFire = 0.5f; //if (Time.time >= nextTimeToFire) { shooting.Shoot(); //nextTimeToFire = Time.time + 1f / 1; //} } }
void Update() { if (!MenuManager.onPause) { move = Input.GetAxisRaw("Horizontal"); if (Input.GetButtonUp("Jump") && canJump) { jump = true; canJump = false; Invoke("JumpOn", 0.1f); } else { jump = false; } if (Input.GetKeyUp(KeyCode.C)) { crouch = !crouch; movement.head.enabled = crouch; } if (Input.GetButtonUp("Fire1") && !crouch) { shooting.Shoot(); } if (Input.GetButtonUp("Fire1") && crouch) { movement.Kus(); FindObjectOfType <SoundManager>().Play("PlayerKus"); kus.makeKus(); } } }
// Update is called once per frame protected void Update() { if (IsPlayerInactive == false) { // Handle the horizontal and Vertical movements movement.HandleMovement(); // Handle shooting if ((Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.LeftShift)) && shooting.CanShoot == true) { shooting.Shoot(movement.IsTurningLeft); GameEngine.SoundManager.Play(AirmanLevelSounds.SHOOTING); } // Handle health... if (health.IsHurting) { if (Time.time - health.HurtingTimer >= health.HurtingDelay) { movement.IsHurting = false; health.IsHurting = false; } } // Assign the appropriate texture to the player... AssignTexture(); if (transform.position.z != 0) { Vector3 pos = transform.position; pos.z = 0; transform.position = pos; } } }
private void Update() { if (photonView.isMine == false) { return; } m_UpdateTargetTimer += Time.deltaTime; m_UpdateTargetPointTimer += Time.deltaTime; if (m_UpdateTargetTimer >= updateTargetTime) { SelectNewTarget(); m_UpdateTargetTimer = 0; } if (m_UpdateTargetPointTimer >= updateTargetPointTime) { UpdateTargetPoint(); m_UpdateTargetPointTimer = 0; } float lookTarget = centerAngle + angleRadius * Mathf.Sin(Time.time * rotateSpeed); Movement.SetLookTarget(lookTarget); if (Target != null && m_TargetPoint != Vector3.zero) { float ang = GetAngle(m_TargetPoint); if (ang < shootAngleThreshold) { Shooting.Shoot(); } } }
private void CheckShooting() { isMoving = true; Vector3 targetPosition = target.transform.position; Vector3 position = this.gameObject.transform.position; //sqrmagnitude is faster if ((targetPosition - position).sqrMagnitude < 625.0) //25*25 { //check direction and height now if (((targetPosition.x < position.x) && (!isFacingRight)) || ((targetPosition.x > position.x) && (isFacingRight))) { if (Mathf.Abs(targetPosition.x - position.x) < 3.0f) { isMoving = false; } if (Mathf.Abs(targetPosition.y - position.y) < 5.0f) { shooter.Shoot(isFacingRight, false); } } } }
private void Update() { Shooting.Shoot(); Movement.SetLookTarget(m_LookAngle); m_LookAngle += Time.deltaTime * rotateSpeed; }
public IEnumerator Run(Move move, Shooting shooting) { while (true) { shooting.Shoot(); var random = Random.value; if (random < 0.15) { move.Down(); } else if (random >= 0.15 && random < 0.3) { move.Up(); } else if (random >= 0.3 && random < 0.45) { move.Right(); } else if (random >= 0.45 && random < 0.6) { move.Left(); } yield return(new WaitForSeconds(1)); } }
void Update() { if (Input.GetKey(KeyCode.Mouse0)) { shooting.Shoot(aiming.dir); } }
private void Update() { if (Input.GetButtonDown("Jump")) { jump = true; animator.SetBool("Jumping", true); } if (Input.GetButtonDown("Crouch")) { crouching = true; } else if (Input.GetButtonUp("Crouch")) { crouching = false; } if (Input.GetButtonDown("Shoot") && isGrounded) { animator.SetBool("Shooting", true); shootingController.Shoot(); Invoke("Wait", 0.5f); } if (Input.GetButtonDown("BurstShoot") && isGrounded) { animator.SetBool("Shooting", true); shootingController.BurstShoot(); Invoke("Wait", 1f); } }
private void Update() { if (Tank.IsLocal == false) { return; } if (Tank.IsAlive == false) { return; } if (GamemodeControl.Current == null) { Movement.SetTargetDirection(Vector3.zero); return; } UpdateCursorPosition(); Movement.SetLookTarget(GetLookTarget()); Movement.SetTargetDirection(GetTargetDirection()); Movement.SetBoostHeld(Input.GetButton("Boost")); if (Input.GetButtonDown("Shoot")) { Shooting?.Shoot(); } if (Input.GetButtonDown("Landmine")) { TankLandmine?.Use(); } }
private void attack() { if (Time.time - lastShoot >= 1) { lastShoot = Time.time; shooting.Shoot(); } }
//This method is used when the player interacts with a locked door. If the player has a key, it will remove 1 key, and activate the method for the doors script public void AmmoCheck() { if (ammo >= 1f) { hasAmmo.Shoot(); ammo--; } }
public void TypeLetter(char letter) { if (hasActiveWord) { if (activeWord.GetNextLetter() == letter) { clearedLetters++; activeWord.TypeLetter(); shooter.Shoot(activeWord); } } else { foreach (Word word in words) { if (word.GetNextLetter() == letter) { clearedLetters++; activeWord = word; hasActiveWord = true; word.TypeLetter(); shooter.Shoot(word); break; } } } if (hasActiveWord && activeWord.WordTyped()) { hasActiveWord = false; words.Remove(activeWord); if (activeWord.wordType == WordTypes.TIME_BOMB) { StartCoroutine(FreezeTimer()); } clearedWords++; speedCounter++; } if (speedCounter >= increaseSpeedStep) { wordTimer.IncreaseSpeed(); wordFallSpeed += .1f; speedCounter = 0; } }
public override void OnPointerUp(PointerEventData eventData) { base.OnPointerUp(eventData); if (gameObject.name == "AimingJoystick") { shooting.Shoot(); } }
/// <summary> /// Обработка ввода данных. /// </summary> private void Update() { runDirection.x = Input.GetAxisRaw("Horizontal"); runDirection.z = Input.GetAxisRaw("Vertical"); runDirection = runDirection.normalized; isRunning = runDirection.magnitude == 0 ? false : true; // Координаты прицела + смещения из инспектора crosshairPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f); crosshairWorldPositionWithOffsets = mainCamera.ScreenToWorldPoint(new Vector3(crosshairPosition.x, crosshairPosition.y, zOffsetHeadArms)); leftArmAimPosition = mainCamera.ScreenToWorldPoint(new Vector3(crosshairPosition.x + xOffsetLeftArm, crosshairPosition.y, zOffsetHeadArms)); rightArmAimPosition = mainCamera.ScreenToWorldPoint(new Vector3(crosshairPosition.x + xOffsetRightArm, crosshairPosition.y, zOffsetHeadArms)); // Прицеливание if (Input.GetMouseButtonDown(1)) { isAiming = true; } if (Input.GetMouseButtonUp(1) && !Input.GetMouseButton(0)) { isAiming = false; } // Стрельба if (Input.GetMouseButton(0)) { isAiming = true; shooting.Shoot(crosshairWorldPositionWithOffsets); } if (Input.GetMouseButtonUp(0) && !Input.GetMouseButton(1)) { isAiming = false; } // Прыжок или поднятие if (Input.GetKeyDown(KeyCode.Space)) { if (isGrounded && isStanding) { Jump(); } else if (isGrounded && !isStanding && !isTryingToStand) { isTryingToStand = true; GetUp(); } } }
private void Shoot() { if (IsPlayerTooFarToShoot()) { _state = PatrolEnemyWithGunStates.Patrolling; _aiDestinationSetter.enabled = true; _aiPath.enabled = true; _seeker.enabled = true; SetAiDestination(_currentTarget); return; } if (Time.time < _nextShotTime) { return; } const float failAxisProbability = 0.5f; const float errorMargin = 1f; var failXRandom = Random.value; var failYRandom = Random.value; Vector2 shotTarget = _player.transform.position; if (failXRandom < failAxisProbability) { var xError = Random.Range(-errorMargin, errorMargin); shotTarget.x = shotTarget.x + xError; Debug.Log($"Failed x by {xError}"); } if (failYRandom < failAxisProbability) { var yError = Random.Range(-errorMargin, errorMargin); shotTarget.y = shotTarget.y + yError; Debug.Log($"y x by {yError}"); } var shot = SharedGunShotPool.Instance.GetNextShot(); shot.SetActive(true); shot.GetComponent <SpriteRenderer>().color = _shotColor; Vector2 position = transform.position; Shooting.Shoot(position, (shotTarget - position), shot, _enemy.HitPoints); SharedGunShotPool.Instance.ReturnShot(shot); _gunTriangle.SetActive(true); Debug.Log($"Angle before = {transform.rotation.eulerAngles}"); transform.right = _player.transform.position - transform.position; Debug.Log($"Angle after = {transform.rotation.eulerAngles}"); StartCoroutine(DisableGunTriangle()); const float minSecondsBetweenShots = .1f; const float maxSecondsBetweenShots = 1f; _nextShotTime = Time.time + Random.Range(minSecondsBetweenShots, maxSecondsBetweenShots); }
private void Update() { //Si está en Shooting intenta disparar y reduce el cooldown del disparo if (state == EnemyState.Shooting) { shooting.Cooldown(); shooting.Shoot(); } }
void OnTriggerEnter(Collider collider) { if (collider.CompareTag("Player") && coinManager.inSlowTimePower == false) { gameTimeManager.SlowTimeDown(0.2f); GetComponent <BoxCollider>().enabled = false; StartCoroutine(shooter.Shoot()); } }
private void ShootAtAll() { var attackables = FindObjectsOfType <Attackable>(); foreach (var attackable in attackables) { shooting.Shoot(attackable); } shooting.lastAttack = Time.time; }
void Update() { if (Input.GetButton("Fire1") && Time.time > nextFire) { nextFire = Time.time + fireRate; shooting.Shoot(shot, shotSpawn.position, shotSpawn.rotation); GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("SoundEffSliderVolumeLevel", GetComponent <AudioSource>().volume);; GetComponent <AudioSource>().Play(); } }
private void Update() { if (shooting.IsReadyToAttack()) { SetLockedOnTarget(); if (lockedOnTarget) { shooting.Shoot(lockedOnTarget); shooting.lastAttack = Time.time; } } }
public void Aiming() { RaycastHit2D hitRight = Physics2D.Raycast(rifle.FirePoint.position, transform.right); Sensor(); if (timer > 0) { timer--; } if (timer < 1 && hitRight && hitRight.transform.tag == "Player") { rifle.Shoot(); timer = timeToShoot; } }
/// <summary> /// Dependiendo del estado en el que esté, acualiza su comportamiento /// </summary> private void Update() { switch (state) { case EnemyState.Fleeing: followDirection.MoveTowards((transform.position - player.transform.position).normalized); break; case EnemyState.Shooting: shooting.Cooldown(); shooting.Shoot(); break; } anim.SetFloat("Velocity", rb.velocity.magnitude); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == ("Turret")) { _shooting = other.GetComponent <Shooting> (); } if (other.gameObject.tag == ("Enemy")) { _shooting.Shoot(); Destroy(gameObject); } if (other.gameObject.name == ("CastLineTurret")) { _raycast = other.gameObject; } }
void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 100); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { _playerMovement.LookAt(hit.point); } if (Input.GetButtonDown("Fire1")) { _playerShoot.Shoot(); } }
private void Update() { if (Input.GetButtonDown("ChangeShooting")) { Weapon.ChangeActiveWeapon(); } else if (Input.GetButtonDown("Fire1")) { if (Weapon.cartridge.ContainsKey(Weapon.activeWeapon) && Weapon.cartridge[Weapon.activeWeapon] > 0) { shooting.Shoot(unit, Weapon.activeWeapon); Weapon.cartridge[Weapon.activeWeapon]--; } } }
public bool Fire() { if (!IsThrown) { if (AmmoLoaded > 0) { Shooting shooting = GameObject.Find("Player").GetComponent <Shooting>(); if (shooting.Shoot()) { AmmoLoaded--; } else { return(false); } if (shooting.SilencedShots <= 0 && WeaponType == Type.Pistol) { WeaponSprite = Resources.Load <Sprite>("Sprites/pistol2"); } return(true); } //This part will run when AmmoLoaded <= 0 since the function did not return yet. GameObject.Find("Game Manager").GetComponent <AudioManager>().PlaySound(AudioManager.SoundEffect.FireEmpty); return(false); } else { if (AmmoStandby > 0 && GameObject.Find(DataDriven.thrownObjName) == null && GameObject.Find(DataDriven.explosionName) == null) { //Throw weapon if one isn't already thrown and visible. AmmoStandby--; switch (WeaponType) { case Type.Grenade: Grenade.Spawn(GameObject.Find("Player")); break; } return(true); } //This part will run when AmmoStandby <= 0 and a thrown weapon is not found since the function did not return yet. return(false); } }
// Update is called once per frame private void Update() { horizontal = Input.GetAxisRaw("Horizontal"); if (horizontal == 1 || horizontal == -1) { lastHorizontal = horizontal; } if (Input.GetButtonDown("Jump")) { ifJump = true; } if (Input.GetButtonDown("Dash")) { dashSpeed = dashMultiplier; } //Get button (not get button down) because this let player hold the button if (Input.GetButton("Attack")) { isAttacking = true; shooting.Shoot(); } }
private void FixedUpdate() { float h; float v; int shoot; if (Application.platform == RuntimePlatform.Android) { h = joystick.Horizontal; v = joystick.Vertical; shoot = 0; } else { h = CrossPlatformInputManager.GetAxis("Horizontal"); v = CrossPlatformInputManager.GetAxis("Vertical"); shoot = (int)Math.Round(CrossPlatformInputManager.GetAxis("Shoot")); } _mCar.Move(h, v, v); if (shoot == 1) { _mShooting.Shoot(); } }