private void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { m_Shooter.Shoot(); } }
// Update is called once per frame void Update() { shooter.Shoot(); if (attackState == AttackState.Chase) { // Do state behavior Chase(GameManager.Instance.Players[0]); // Check for transitions if (health.CurrentHealth < 3) { attackState = AttackState.Flee; } } else if (attackState == AttackState.Flee) { // Do state behavior Flee(GameManager.Instance.Players[0]); // Check for transitions if (health.CurrentHealth >= 3) { attackState = AttackState.Chase; } } else { Debug.LogWarning("[AIController2] Unhandled State in Update Method"); } }
private void ChaseAndFire(GameObject target) { float attackRange = 20.0f; if (Vector3.Distance(transform.position, target.transform.position) < attackRange) { shooter.Shoot(); } }
public void ShootTurret() { if (_tankState == TankState.Idle) { _currentTimer = 0; _maxTimer = RELOAD_DELAY; _tankShooter.Shoot(boxCollider); _tankState = TankState.Shooting; } else { OnTankFinished?.Invoke(0); } }
// Update is called once per frame void Update() { shooter.Shoot(); if (attackState == AttackState.Chase) { if (avoidenceStage != AvoidenceStage.NotAvoiding) { Avoid(); } else { Chase(GameManager.Instance.Players[0]); } } }
private void RotateToPlayer() { Vector3 toPlayerDirection = Player.Instance.transform.position - transform.position; float toPlayerAngle = Vector3.Angle(toPlayerDirection, m_TurretRotator.Turret.forward); if (toPlayerAngle > DirectionAngleTreshold) { Vector2 topDownDirection = new Vector2(toPlayerDirection.x, toPlayerDirection.z); m_TurretRotator.RotateTo(topDownDirection); } else { m_TankShooter.Shoot(); StartWaiting(); } }
// Update is called once per frame void Update() { switch (inputScheme) { case InputScheme.WASD: // handling movement if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveSpeed); } else if (Input.GetKey(KeyCode.S)) { motor.Move(-data.moveSpeed); } else { motor.Move(0); } // handling rotation if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.turnSpeed); } else if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.turnSpeed); } // shooting if (Input.GetKey(KeyCode.Space)) { shooter.Shoot(); } break; case InputScheme.arrowKeys: break; default: Debug.LogError("[InputController] Input scheme not implemented"); break; } }
public void Chase(GameObject target) { if (motor.RotateTowards(target.transform.position, data.turnSpeed)) { //do nothing } else if (!CanMove(data.moveSpeed)) { avoidanceStage = AvoidanceStage.ObstacleDetected; } else { if (Vector3.SqrMagnitude(transform.position - target.transform.position) >= (closeEnough * closeEnough)) { motor.Move(data.moveSpeed); } shooter.Shoot(); } }
//Fire a bullet from the tank [NOW USES COOLDOWN] private void Shoot() { //Call Shoot() from Tank's TankShooter component //shooter.Shoot(); //If the tank is able to shoot if (data.canShoot) { //Shoot a bullet shooter.Shoot(); //Set canShoot to false data.canShoot = false; //Reset cooldown until tank can shoot again data.timeUntilCanShoot = data.fireRate; } //Note: Shooting cooldown timer is handled in Update() }
// Update is called once per frame void Update() { Vector3 moveVector = Vector3.zero; //Create our variable, set no movement Vector3 turnVector = Vector3.zero; //Create our variable, set no movement if (Input.GetKey(forwardKey)) //forward key is pressed { moveVector = data.tf.forward * data.forwardSpeed; //set forward data } else if (Input.GetKey(reverseKey)) //reverse key is pressed { moveVector = data.tf.forward * -data.reverseSpeed; //set reverse data } if (Input.GetKey(turnClockKey)) //clockwise key is pressed { turnVector = new Vector3(0, data.turnSpeed, 0); //set clockwise data } else if (Input.GetKey(turnCounterClockKey)) //counterclockwise key is pressed { turnVector = new Vector3(0, -data.turnSpeed, 0); //set counterclockwise data } if (Input.GetKey(fireBullet)) //fire bullet button is pressed { ts.Shoot(); //fire bullet } if (Input.GetKey(mapView)) { //TODO: add map view } if (Input.GetKey(exitGame)) { Application.Quit(); } //actually move SendMessage("Move", moveVector, SendMessageOptions.DontRequireReceiver); //tell TankMover to move in direction from pressed key SendMessage("Rotate", turnVector, SendMessageOptions.DontRequireReceiver); //tell TankMover to rotate in direction from pressed key }
// Update is called once per frame void Update() { //Shooter Controls //---------------------------------------------- //If the player is able to shoot if (data.canShoot) { if (Input.GetKeyDown(KeyCode.Space)) //Will need to have a shoot button for each player { //Shoot shooter.Shoot(); data.canShoot = false; data.timeUntilCanShoot = data.fireRate; } } if (data.timeUntilCanShoot > 0) { data.timeUntilCanShoot -= Time.deltaTime; } else { data.canShoot = true; } //Movement Controls //---------------------------------------------- isMoving = false; //player is not moving this frame unless movement input is pressed switch (input) { case InputScheme.WASD: //Forward [W] if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveSpeed); isMoving = true; } //Reverse [D] if (Input.GetKey(KeyCode.S)) { //TODO: Reverse Speed motor.Move(-data.moveSpeed); isMoving = true; } //Turn Right [D] if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.rotateSpeed); } //Turn Left [A] if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.rotateSpeed); } break; case InputScheme.arrowKeys: //Forward [UP ARROW] if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); isMoving = true; } //Reverse [DOWN ARROW] if (Input.GetKey(KeyCode.DownArrow)) { //TODO: Reverse Speed motor.Move(-data.moveSpeed); isMoving = true; } //Turn Right [RIGHT ARROW] if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } //Turn left [LEFT ARROW] if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.rotateSpeed); } break; } //If the tank is not moving, pass a speed of 0 if (!isMoving) { //Pass a speed of 0 to the Simple Move Controller so physics are still detected motor.Move(0.0f); } }
// Update is called once per frame void Update() { //if the player can shoot then it will get the key of space and shootbut if can shoot is false then it will wait to fire if (canShoot) { if (Input.GetKeyDown(KeyCode.Space)) { // Shoot shooter.Shoot(); canShoot = false; timeUntilCanShoot = data.fireRate; } } //if you are wait if it shoots the time until shoot will subtract from the time till you can unless you can shoot // Determine if the player can shoot again yet. if (timeUntilCanShoot > 0) { timeUntilCanShoot -= Time.deltaTime; } else { canShoot = true; } switch (input) { case InputScheme.arrowKeys: if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(-data.moveSpeed); } if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.rotateSpeed); } break; case InputScheme.WASD: if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.S)) { motor.Move(-data.moveSpeed); } if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.rotateSpeed); } break; } }
private void Shoot() { shooter.Shoot(); }
// Update is called once per frame void Update() { shooter.Shoot(); // We need to see if we are already at the waypoint. // If we are not at the waypoint, turn to face it. if (motor.RotateTowards(waypoints[currentWaypoint].transform.position, data.turnSpeed)) { // Do nothing! } // If we are facing the waypoint, move towards it. else { // Move forward. motor.Move(data.moveSpeed); } // If we've arrived at our waypoint, then go to the next one. if (loopType == LoopType.Stop) { if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough)) { if (currentWaypoint < (waypoints.Length - 1)) { currentWaypoint++; } } } else if (loopType == LoopType.Loop) { if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough)) { if (currentWaypoint < (waypoints.Length - 1)) { currentWaypoint++; } else { currentWaypoint = 0; } } } else if (loopType == LoopType.PingPong) { if (isLoopingForward) { if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough)) { if (currentWaypoint < (waypoints.Length - 1)) { currentWaypoint++; } else { isLoopingForward = false; } } } else { if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough)) { if (currentWaypoint > 0) { currentWaypoint--; } else { isLoopingForward = true; } } } } else { Debug.LogWarning("[AIController] Unexpected LoopType"); } }
// Update is called once per frame void Update() { shooter.Shoot(); // face waypoint if (motor.RotateTowards(waypoints[currentWaypoint].transform.position, data.turnSpeed)) { // do nothing } // move toward waypoint else { motor.Move(data.moveSpeed); } // we need to see if we're already at waypoint if (loopType == LoopType.Stop) { if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough)) { if (IsNotAtFinalWaypoint()) { currentWaypoint++; } } } else if (loopType == LoopType.Loop) { if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough)) { if (IsNotAtFinalWaypoint()) { currentWaypoint++; } else { currentWaypoint = 0; } } } else if (loopType == LoopType.PingPong) { if (isLoopingForward) { if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough)) { if (IsNotAtFinalWaypoint()) { currentWaypoint++; } else { isLoopingForward = false; } } } else { if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough)) { if (currentWaypoint > 0) { currentWaypoint--; } else { isLoopingForward = true; } } } } else { Debug.LogWarning("[EnemyAI] Unexpected LoopType"); } }
// Update is called once per frame void Update() { //Switches from arrow keys or WASD depending on the inspector's choice switch (input) { //Control scheme for the arrow keys case InputScheme.arrowKeys: if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(-data.moveSpeed); } if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.rotateSpeed); } break; //Control scheme for WASD case InputScheme.WASD: if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.S)) { motor.Move(-data.moveSpeed); } if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.rotateSpeed); } break; case InputScheme.arrowKeys2P: if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(-data.moveSpeed); } if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.rotateSpeed); } break; } //If the tank is able to shoot... if (canShoot) { if (input == InputScheme.WASD) { if (Input.GetKeyDown(KeyCode.LeftShift)) { //Shooting shooter.Shoot(); //Cooldown time canShoot = false; timeUntilCanShoot = data.fireRate; } } else if (input == InputScheme.arrowKeys2P) { if (Input.GetKeyDown(KeyCode.RightShift)) { //Shooting shooter.Shoot(); //Cooldown time canShoot = false; timeUntilCanShoot = data.fireRate; } } else { //If the player presses space... if (Input.GetKeyDown(KeyCode.Space)) { //Shooting shooter.Shoot(); //Cooldown time canShoot = false; timeUntilCanShoot = data.fireRate; } } } //Cooldown if (timeUntilCanShoot > 0) { timeUntilCanShoot -= Time.deltaTime; } else { canShoot = true; } }
// Update is called once per frame void Update() { if (canShoot) { if (Input.GetKeyDown(KeyCode.Space)) { // Shoot shooter.Shoot(); canShoot = false; timeUntilCanShoot = data.fireRate; } } // Determine if the player can shoot again yet. if (timeUntilCanShoot > 0) { timeUntilCanShoot -= Time.deltaTime; } else { canShoot = true; } switch (input) { case InputScheme.arrowKeys: if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(-data.moveSpeed); } if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.rotateSpeed); } break; case InputScheme.WASD: if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.S)) { motor.Move(-data.moveSpeed); } if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.rotateSpeed); } break; } }