protected virtual void Awake() { _playerShip = FindObjectOfType <PlayerShip>(); _player = FindObjectOfType <Player>(); _weaponSelecded = FindObjectOfType <WeaponSelected>(); _shootCooldown = 0.0f; }
private void Awake() { _text = GetComponent <Text>(); _player = FindObjectOfType <Player>(); _weaponSelected = FindObjectOfType <WeaponSelected>(); }
void Inputs() { if (weapons != null) { switch (weapons.type) { case Weapons.WeaponType.subMachineGun: if (Input.GetMouseButton(0) && !ActivateDash) { if (weapons.GetCanShoot()) { source.PlayOneShot(soundShootSMG, 0.15f); lastMousePosition = new Vector3(mousePosition.x, mousePosition.y, 0f) + new Vector3((float)UnityEngine.Random.Range(-1.75f, 1.75f), (float)UnityEngine.Random.Range(-1.75f, 1.75f), 0f); if (aimingRight) { if (cannonPos[2] != null && cannonPos[2].activeSelf) { weapons.ShootSubmachineGun(cannonPos[2].transform.position); } } else if (aimingLeft) { if (cannonPos[3] != null && cannonPos[3].activeSelf) { weapons.ShootSubmachineGun(cannonPos[3].transform.position); } } if (screenShake != null) { StartCoroutine(screenShake.Shake(weapons.GetShakeDuration(), weapons.GetShakeMagnitude(Weapons.WeaponType.subMachineGun))); } } } break; case Weapons.WeaponType.Shotgun: if (Input.GetMouseButtonDown(0) && !ActivateDash) { if (weapons.GetCanShoot()) { source.PlayOneShot(soundShootShotgun); lastMousePosition = new Vector3(mousePosition.x, mousePosition.y, 0f); if (aimingRight) { if (cannonPos[0] != null && cannonPos[0].activeSelf) { weapons.ShootShotgun(cannonPos[0].transform.position); } } else if (aimingLeft) { if (cannonPos[1] != null && cannonPos[1].activeSelf) { weapons.ShootShotgun(cannonPos[1].transform.position); } } if (screenShake != null) { StartCoroutine(screenShake.Shake(weapons.GetShakeDuration(), weapons.GetShakeMagnitude(Weapons.WeaponType.Shotgun))); } } } break; case Weapons.WeaponType.Revolver: if (Input.GetMouseButton(0) && !ActivateDash) { if (weapons.GetCanShoot()) { source.PlayOneShot(soundShootRevolver); lastMousePosition = new Vector3(mousePosition.x, mousePosition.y, 0f) + new Vector3((float)UnityEngine.Random.Range(-0.5f, 0.5f), (float)UnityEngine.Random.Range(-0.5f, 0.5f), 0f); if (aimingRight) { if (cannonPos[4] != null && cannonPos[4].activeSelf) { weapons.ShootRevolver(cannonPos[4].transform.position); } } else if (aimingLeft) { if (cannonPos[5] != null && cannonPos[5].activeSelf) { weapons.ShootRevolver(cannonPos[5].transform.position); } } if (screenShake != null) { StartCoroutine(screenShake.Shake(weapons.GetShakeDuration(), weapons.GetShakeMagnitude(Weapons.WeaponType.Shotgun))); } } } break; } } if (Input.GetKeyDown(KeyCode.W)) { playerAnims.StartIdleAnim(); } if (Input.GetKeyDown(KeyCode.S)) { playerAnims.StartIdleAnim(); } if (Input.GetKeyDown(KeyCode.A)) { spriteRenderer.flipX = true; } if (Input.GetKey(KeyCode.A)) { playerAnims.StartAnimMoveSide(); } if (Input.GetKeyDown(KeyCode.D)) { spriteRenderer.flipX = false; } if (Input.GetKey(KeyCode.D)) { playerAnims.StartAnimMoveSide(); } if (Input.GetMouseButton(1)) { if (hitCollider != null) { StartCoroutine(StartCollider(hitCollider)); } } if (Input.GetKeyDown(KeyCode.Alpha1)) { weapons.type = Weapons.WeaponType.subMachineGun; selection = WeaponSelected.SMG; } if (Input.GetKeyDown(KeyCode.Alpha2)) { weapons.type = Weapons.WeaponType.Shotgun; selection = WeaponSelected.Shotgun; } if (Input.GetKey(KeyCode.Alpha3)) { weapons.type = Weapons.WeaponType.Revolver; selection = WeaponSelected.Revolver; } if (Input.GetKeyDown(KeyCode.Space) && canActivateDash && movement != Vector3.zero) { source.PlayOneShot(soundDash); playerAnims.StartDashAnim(); ActivateDash = true; canActivateDash = false; } }