private void InputHandler() { switch (input) { case InputScheme.WASD: if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveSpeed); } else if (Input.GetKey(KeyCode.S)) { motor.Move(data.backwardMoveSpeed * -1); } else { motor.Move(0); } if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.rotateSpeed); } else if (Input.GetKey(KeyCode.A)) { motor.Rotate(data.rotateSpeed * -1); } else { motor.Rotate(0); } if (Input.GetKeyDown(KeyCode.Space)) { motor.Fire(); } break; case InputScheme.arrowKeys: if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); } else if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(data.backwardMoveSpeed * -1); } else { motor.Move(0); } if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } else if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(data.rotateSpeed * -1); } else { motor.Rotate(0); } if (Input.GetKeyDown(KeyCode.Keypad0)) { motor.Fire(); } break; default: Debug.LogError("[InputManager]: Undefined Input Scheme"); break; } }
void Search() { motor.Rotate(data.turnSpeed); }
// 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; } }
// 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; } //If the tank is able to shoot... if (canShoot) { //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; } }
public void turnToAvoid() { motor.Rotate(data.rotateSpeed); }
// Update is called once per frame void Update() { motor.Move(data.moveSpeed); motor.Rotate(data.rotateSpeed); }
// Update is called once per frame void Update() { motor.Move(1.0f); motor.Rotate(1.0f); gameObject.SendMessage("Shoot", SendMessageOptions.DontRequireReceiver); }
private void Update() { switch (input) { case InputScheme.WASD: //case for using WASD for player 1 if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveForwardSpeed); } if (Input.GetKey(KeyCode.S)) { motor.Move(-data.moveBackwardSpeed); } if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.turnLeftSpeed); } if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.turnRightSpeed); } break; } switch (input) { case InputScheme.ArrowKeys: //case for using arrows for player 2 if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveForwardSpeed); } if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(-data.moveBackwardSpeed); } if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.turnRightSpeed); } if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.turnLeftSpeed); } break; } // Track the current state of the fire button and make decisions based on the current launch force. if (Time.time > data.fireRate) { if (firing.currentLaunchForce >= data.maxLaunchForce && !firing.fired) { // at max xharge not yet fired firing.currentLaunchForce = data.maxLaunchForce; firing.Fire(); } else if (Input.GetButtonDown("Fire1")) { //has the button been pressed for the first time firing.fired = false; firing.currentLaunchForce = data.minLaunchForce; //sets back to minimum } else if (Input.GetButton("Fire1") && !firing.fired) { //holding the button firing.currentLaunchForce += firing.chargeSpeed * Time.deltaTime; //increases force accordingly } else if (Input.GetButtonUp("Fire1") && !firing.fired) { //release the button firing.Fire(); } firing.nextFire = Time.time + data.fireRate; } if (data.playerNumber == 2) //continuous shooting for player 2 { if (Time.time > data.fireRate) { firing.nextFire = Time.time + data.fireRate; firing.Fire(); } } }
// 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); } // Handle Shooting if (Input.GetKey(KeyCode.Space)) { shooter.Shoot(); } break; case InputScheme.arrowKeys: // Handling Movement if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); } else if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(-data.moveSpeed); } else { motor.Move(0); } // Handling Rotation if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.turnSpeed); } else if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.turnSpeed); } // Handle Shooting if (Input.GetKey(KeyCode.M)) { shooter.Shoot(); } break; default: Debug.LogError("[InputController] Input scheme not implemented."); break; } }
// Update is called once per frame void Update() { //Checking to see which input scheme we are using switch (input) { //If we are using the arrow keys case InputScheme.arrowKeys: //checking to see if the player pressed the up arrow if (Input.GetKey(KeyCode.UpArrow)) { //moving the tank forward motor.Move(data.moveSpeed); } //Checking to see if the player pressed the down arrow else if (Input.GetKey(KeyCode.DownArrow)) { //Moving the player backward motor.Move(-data.moveSpeed); } //Checking to see if the user pressed the left arrow else if (Input.GetKey(KeyCode.LeftArrow)) { //Rotating the player to the left motor.Rotate(-data.rotateSpeed); } //Checking to see if the player pressed the right arrow else if (Input.GetKey(KeyCode.RightArrow)) { //Rotating the player to the right motor.Rotate(data.rotateSpeed); } //If the player did not press anything else { //Do not move the player at all motor.Move(0); } break; case InputScheme.WASD: //Checking to see if the user pressed the W key if (Input.GetKey(KeyCode.W)) { //Move the player forward motor.Move(data.moveSpeed); } //Checking to see if the user pressed the S Key else if (Input.GetKey(KeyCode.S)) { //Move the player backward motor.Move(-data.moveSpeed); } //Checking to see if the user pressed the A key else if (Input.GetKey(KeyCode.A)) { //Rotate the player to the left motor.Rotate(-data.rotateSpeed); } //Checking to see if the user pressed the D Key else if (Input.GetKey(KeyCode.D)) { //Rotate the user to the right motor.Rotate(data.rotateSpeed); } //If the user did not press anything else { //Do not move the player at all motor.Move(0); } break; } //Subtracting real time from our timer value Timer -= Time.deltaTime; //If timer is less than one if (Timer < 1) { //Then the tank is able to shoot CanShoot = true; //Reset the timer for the delay between shots Timer = ShootDelay; } //If the player presses the spacebar if (Input.GetKeyDown(KeyCode.Space)) { //if the player can shoot if (CanShoot) { //Shoot the bullet motor.Shoot(data.Bullet, data.FirePoint); //So we can shoot again once the timer hits zero CanShoot = false; } } }
// Update is called once per frame void Update() { motor.Move(3); motor.Rotate(180); }
void HandleInput() { switch (input) { case InputScheme.arrowKeys: //Handle Movement for the arrow keys if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); } else if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(-data.moveSpeed); } else { motor.Move(0); } //Handle rotation for the arrow keys if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } else if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.rotateSpeed); } else { motor.Move(0); } break; case InputScheme.WASD: //Handle movement for WASD if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveSpeed); } else if (Input.GetKey(KeyCode.S)) { motor.Move(-data.moveSpeed); } else { motor.Move(0); } //Handle rotation for WASD if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.rotateSpeed); } else if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.rotateSpeed); } else { motor.Move(0); } break; default: Debug.LogError("[InputManager] Undefined input scheme"); break; } }
//Controls the two movement schemes implemented void HandleInputs() { switch (input) { //Player1 Movement set case inputScheme.WASD: if (Input.GetKey(KeyCode.W) && data.curFuel >= 0) { motor.Move(data.moveSpeedForward); isMoving = true; } else if (Input.GetKey(KeyCode.S) && data.curFuel >= 0) { motor.Move(-data.moveSpeedBack); isMoving = true; } else { motor.Move(0); isMoving = false; } if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.rotateSpeed); } else if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.rotateSpeed); } else { motor.Rotate(0); } if (Input.GetKeyDown(KeyCode.Space)) { shoot.ShootBullet(); } if (Input.GetKeyDown(KeyCode.F)) { health.Death(); } break; //Player2 movement set case inputScheme.arrowKeys: if (Input.GetKey(KeyCode.UpArrow) && data.curFuel >= 0) { motor.Move(data.moveSpeedForward); isMoving = true; } else if (Input.GetKey(KeyCode.DownArrow) && data.curFuel >= 0) { motor.Move(-data.moveSpeedBack); isMoving = true; } else { motor.Move(0); isMoving = false; } if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } else if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.rotateSpeed); } else { motor.Rotate(0); } if (Input.GetKeyDown(KeyCode.Mouse0)) { shoot.ShootBullet(); } if (Input.GetKeyDown(KeyCode.End)) { health.Death(); } break; //If no movement is selected default: Debug.LogError("Input Scheme not selected"); break; } }
//Run once per frame and check for user input void Update() { switch (input) { case InputScheme.WASD: { if (Input.GetKey(KeyCode.W)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.A)) { motor.Rotate(-data.rotateSpeed); } if (Input.GetKey(KeyCode.S)) { motor.Move(-data.reverseSpeed); } if (Input.GetKey(KeyCode.D)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.Space)) { if (gun.isLoaded) { gun.Fire(); } } } break; case InputScheme.ArrowKeys: { if (Input.GetKey(KeyCode.UpArrow)) { motor.Move(data.moveSpeed); } if (Input.GetKey(KeyCode.LeftArrow)) { motor.Rotate(-data.rotateSpeed); } if (Input.GetKey(KeyCode.DownArrow)) { motor.Move(-data.reverseSpeed); } if (Input.GetKey(KeyCode.RightArrow)) { motor.Rotate(data.rotateSpeed); } if (Input.GetKey(KeyCode.RightControl)) { if (gun.isLoaded) { gun.Fire(); } } } break; } }
// Update is called once per frame void Update() { if (GameManager.instance.multiplayer) { // get a target if (target == null) { targCheck = GameObject.FindGameObjectWithTag("Player").transform; targCheck2 = GameObject.FindGameObjectWithTag("Player2").transform; if (Vector3.Distance(targCheck.position, tf.position) < Vector3.Distance(targCheck2.position, tf.position)) { target = GameObject.FindGameObjectWithTag("Player").transform; } else { target = GameObject.FindGameObjectWithTag("Player2").transform; } } } else { // get a target if (target == null) { target = GameObject.FindGameObjectWithTag("Player").transform; } } if (aiSense == AISense.Patrol) { if (avoidanceStage != 0) { DoAvoidance(); } else { if (motor.RotateTowards(waypoints[currentWaypoint].position, data.rotateSpeed)) { // Do nothing } else { // can we move? if (CanMove(2.0f)) { motor.Move(1.0f); } else { avoidanceStage = 1; } } // check distance to waypoint if (Vector3.SqrMagnitude(waypoints[currentWaypoint].position - tf.position) <= (closeEnough * closeEnough)) { // dont go outside the array if (currentWaypoint < waypoints.Length - 1) { currentWaypoint++; } else { currentWaypoint = 0; } } } // check for changes if (Vector3.Distance(target.position, tf.position) <= aiSenseRadius) { ChangeState(AISense.Listen); } } else if (aiSense == AISense.Listen) { // spin and look motor.Rotate(1.0f); // check for change if (CanSee()) { ChangeState(AISense.Chase); } else if (Vector3.Distance(target.position, tf.position) > aiSenseRadius) { ChangeState(AISense.Patrol); } } else if (aiSense == AISense.Chase) { motor.RotateTowards(target.position, data.rotateSpeed); if (CanMove(2.0f)) { motor.Move(1.0f); } else { avoidanceStage = 1; } gameObject.SendMessage("Shoot", SendMessageOptions.DontRequireReceiver); // check for change if (!CanSee()) { ChangeState(AISense.Listen); } } }