// Update is called once per frame private void AddGun() { if (ScoreManager.storageA >= grenadeprice && GrenadeCounter.gCount < GrenadeCounter.maxgrenades) { ScoreManager.AddScore(-grenadeprice); GrenadeCounter.AddGrenade(1); } }
// Update is called once per frame void FixedUpdate() { if (Input.GetAxis(_fireAxis) > 0.9 && Time.fixedTime > nextFire) { nextFire = Time.time + fireRate; Instantiate(shot, shotSpawn.position, shotSpawn.rotation); } if (Input.GetAxis(_nudeAxis) > 0.9 && Time.fixedTime > nextFire && GrenadeCounter.gCount > 0) { nextFire = Time.time + fireRate; Instantiate(grenade, shotSpawn.position, shotSpawn.rotation); GrenadeCounter.AddGrenade(-1); } if (Input.GetButtonDown(_trapAxis) && canSetTrap && TrapCounter.trapCount > 0) { Vector2 butt = new Vector2(0, 0); Instantiate(sectortrap, butt, Quaternion.identity); //StartCoroutine(ActivateTrap()); TrapCounter.AddTrap(-1); canSetTrap = false; } float horizontal = Input.GetAxis(inputName); //"Horizontal"); Vector2 movement = new Vector2(horizontal, 0.0f); var angle = ((horizontal * speed / (2 * radius * Mathf.PI))) * 2 * Mathf.PI; var toDegree = 360f / (2 * Mathf.PI); var prevAngle = tiltAngle; tiltAngle += angle; if (tiltAngle > maxAngle || tiltAngle < -maxAngle) { tiltAngle = prevAngle; } else { var xPos = Mathf.Sin(tiltAngle) * radius; var yPos = -11f + Mathf.Cos(tiltAngle) * radius; transform.position = new Vector3(xPos, yPos, 0f); transform.Rotate(-Vector3.forward * angle * toDegree); } if (inputName == "FlippedHorizontal") { StartCoroutine(NormalInput()); } if (speed < initialSpeed) { StartCoroutine(NormalSpeed()); } }
// Update is called once per frame void FixedUpdate() { if (Input.GetAxis(_fireAxis) > 0.9 && Time.fixedTime > nextFire) { nextFire = Time.time + fireRate; Instantiate(shot, shotSpawn.position, shotSpawn.rotation); } if (Input.GetAxis(_nudeAxis) > 0.9 && Time.fixedTime > nextFire && GrenadeCounter.gCount > 0) { nextFire = Time.time + fireRate; Instantiate(grenade, shotSpawn.position, shotSpawn.rotation); GrenadeCounter.AddGrenade(-1); } if (Input.GetButtonDown(_trapAxis) && canSetTrap && TrapCounter.trapCount > 0) { Vector2 butt = new Vector2(0, 0); Instantiate(trap, butt, Quaternion.identity); //StartCoroutine(ActivateTrap()); TrapCounter.AddTrap(-1); canSetTrap = false; } /*if (Input.GetButtonDown("CreateTrap")) * { * if (trapclick % 2 != 0 && canSetTrap && TrapCounter.trapCount > 0) * { * Vector2 bt = new Vector2(0, 0); * Instantiate(trap, bt, Quaternion.identity); * canSetTrap = false; * TrapCounter.AddTrap(-1); * trapclick++; * * } * else trapclick++; */ float horizontal = Input.GetAxis(inputName); //"Horizontal"); Vector2 movement = new Vector2(horizontal, 0.0f); rb.velocity = movement * speed; if (inputName == "FlippedHorizontal") { StartCoroutine(NormalInput()); } if (speed < initialSpeed) { StartCoroutine(NormalSpeed()); } var pos = rb.position; //rb.position = new Vector2(Mathf.Clamp(rb.position.x, minBound, maxBound), rb.position.y); /*if (Input.GetKey(KeyCode.RightArrow)) * { * rb.AddForce(new Vector2(5,0)); * } * * else if (Input.GetKey(KeyCode.LeftArrow)) * { * rb.AddForce(new Vector2(-5,0)); * } * */ if (pos.x < minBound + 1) //looping behavior, +-1 added to accomodate width of player object { pos.x = maxBound - 1; } if (pos.x > maxBound - 1) { pos.x = minBound + 1; } rb.position = pos; //float h = Input.GetAxis("Horizontal"); //uses the A&D key //player.position += Vector3.right * h * speed; }