void Update() { CurrentWeapon.last_fired += Time.deltaTime; if (CurrentWeapon.last_fired > CurrentWeapon.fire_rate) { look(); CurrentWeapon.Attack(transform.position, looking); CurrentWeapon.last_fired = 0f; } }
void Attack() { if (paused) { return; } Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 direction = (mousePos - transform.position).normalized; Quaternion rotation = Quaternion.LookRotation(Vector3.forward, direction); if (currentWeapon != null) { currentWepScript.Attack(transform.position, mousePos, rotation); } transform.GetChild(1).gameObject.GetComponent <PlayerAnimation>().pAnim = PlayerAnimation.PlayerAnim.ATTACK; }
// Update tied to the refresh rate void Update() { // If we press the default Jump buttons, and are grounded, apply our jump force if (Input.GetButtonDown(myJump) && grounded && GM.allowInput) { GetComponent <Rigidbody2D>().AddForce(new Vector2(0, jump_height)); } // If we press the fire button, prepare to fire bool shoot = Input.GetButtonDown(myShoot); // If we want to fire if (shoot && GM.allowInput) { // Get the weapon for this player Weapons weapon = GetComponent <Weapons>(); // If the player does not have a weapon if (weapon != null) { // Player cannot attack weapon.Attack(false); } } }
private void Attack() { //Debug.Log("live clean"); CurrentWeapon.Attack(transform.position, looking); }
// Update is called once per frame void FixedUpdate() { // Apply Movement float x = Input.GetAxisRaw("Horizontal"); Vector2 v = rigidbody.velocity; v.x = x * speed; if (v.x != 0) { anim.SetBool("running", true); } else { anim.SetBool("running", false); } if (v.x > 0) { sr.flipX = false; } else if (v.x < 0) { sr.flipX = true; } if (Input.GetButtonDown("Jump") && (v.y == 0 || canFly)) { v.y = jumpSpeed; } if (v.y != 0) { anim.SetBool("inAir", true); } else { anim.SetBool("inAir", false); } rigidbody.velocity = v; //attack with a weapon if you have one if (Input.GetButtonDown("Fire1") && currentWeapon != null) { currentWeapon.Attack(); } if (Input.GetButtonDown("Fire2")) { int i = (weapons.IndexOf(currentWeapon) + 1) % weapons.Count; SetCurrentWeapon(weapons [i]); } // Check for out if (transform.position.y < deadZone) { Debug.Log("Current Position " + transform.position.y + " is lower than " + deadZone); GetOut(); } //rigidbody.AddForce(new Vector2(x * speed, 0)); }