private void Shoot(Transform spawnPoint) { Vector3 diff = player.transform.position - spawnPoint.position; if (shootTarget != null) { diff = shootTarget.transform.position - spawnPoint.position; } diff.Normalize(); float projectileSize = Random.Range(0.2f, 0.5f); Vector3 projectileScale = new Vector3(projectileSize, projectileSize, projectileSize); // TODO: better positioning of the projectile Vector3 projectilePosition = new Vector3(spawnPoint.position.x, spawnPoint.position.y, spawnPoint.position.z); GameObject projectile = Instantiate(projectilePrefab, projectilePosition, Quaternion.identity) as GameObject; projectile.transform.localScale = projectileScale; float projectileForce = Random.Range(minProjectileSpeed, maxProjectileSpeed); projectile.GetComponent <Rigidbody>().AddForce(diff * projectileForce); OnShoot?.Invoke(); }
public void ShootTarget(Vector3 targetPosition, Action onShootComplete) { SetAimTarget(targetPosition); // Check for hits Vector3 gunEndPointPosition = turretAimGunEndPointTransform.position; //int layerMask = ~(1 << GameAssets.i.enemyLayer | 1 << GameAssets.i.ignoreRaycastLayer | 1 << GameAssets.i.shieldLayer); int layerMask = ~0; RaycastHit2D raycastHit = Physics2D.Raycast(gunEndPointPosition, (targetPosition - gunEndPointPosition).normalized, Vector3.Distance(gunEndPointPosition, targetPosition), layerMask); GameObject hitObject = null; if (raycastHit.collider != null) { // Hit something targetPosition = (Vector3)raycastHit.point + (targetPosition - gunEndPointPosition).normalized; hitObject = raycastHit.collider.gameObject; } turretAnimator.SetTrigger("Shoot"); OnShoot?.Invoke(this, new CharacterAim_Base.OnShootEventArgs { gunEndPointPosition = turretAimGunEndPointTransform.position, hitObject = hitObject, shootPosition = targetPosition, }); onShootComplete(); }
private void Shoot() { if (isShooting) { if (Time.time > lastShootTime + shootingCooldown) { lastShootTime = Time.time; GameObject bullet = bulletPool.ActivateObject(); if (bullet == null) { return; } OnShoot?.Invoke(); cameraShake.InduceMotion(0.1f); BulletMovement bulletMovement = bullet.GetComponent <BulletMovement>(); bullet.transform.position = transform.position + new Vector3(bulletOffset.x * Mathf.Cos(transform.rotation.eulerAngles.z * Mathf.Deg2Rad), bulletOffset.y * Mathf.Sin(transform.rotation.eulerAngles.z * Mathf.Deg2Rad)); bulletMovement.angle = transform.rotation.eulerAngles.z; bulletMovement.Move(); AudioManager.Instance.PlaySoundAtPosition(shootSFX, bullet.transform.position); } } }
public void CallOnShoot() { if (OnShoot != null) { OnShoot.Invoke(); } }
private void Update() { horizontal = Input.GetAxis("Horizontal"); vertical = Input.GetAxis("Vertical"); Axis = new Vector2(horizontal, vertical); if (Input.GetKey(KeyCode.Q)) { RotateDirection += 1; } else if (Input.GetKey(KeyCode.E)) { RotateDirection += -1; } else { RotateDirection += 0; } if (Input.GetKey(KeyCode.Space)) { if (OnShoot != null) { OnShoot.Invoke(); } } }
public void Shooting() { // Shooting if (Input.GetKey(KeyCode.Space) && Time.time > (lastShotTime + cooldown)) { lastShotTime = Time.time; // Instantiate (Will shoot in awake) Bullet blt = Instantiate(bulletPrefab, transform.position, Quaternion.LookRotation(Vector3.forward, Vector3.up), bulletsContainer.transform).GetComponent <Bullet>(); blt.team = hittable.team; blt.damagePerShot = damagePerShot; blt.speed = bulletSpeed; blt = Instantiate(bulletPrefab, transform.position, Quaternion.LookRotation(Vector3.forward, Quaternion.Euler(0f, 0f, angleSideShots) * Vector3.up), bulletsContainer.transform).GetComponent <Bullet>(); blt.team = hittable.team; blt.damagePerShot = damagePerShot; blt.speed = bulletSpeed; blt = Instantiate(bulletPrefab, transform.position, Quaternion.LookRotation(Vector3.forward, Quaternion.Euler(0f, 0f, -angleSideShots) * Vector3.up), bulletsContainer.transform).GetComponent <Bullet>(); blt.team = hittable.team; blt.damagePerShot = damagePerShot; blt.speed = bulletSpeed; SoundManager.Instance.Play("PlayerShoot", shootSoundVolume); OnShoot?.Invoke(); } }
private void Shoot(Vector2 screenSpaceDirection, Vector2 screenSpacePosition) { if (!holdingBall) { Debug.LogError("wasn't holding ball"); return; } if (alreadyShot) { Debug.LogError("already shot"); return; } //cast a ray to find the target position on the field Ray endPosRay = mainCamera.ScreenPointToRay(screenSpacePosition); RaycastHit endPosHit; if (!Physics.Raycast(endPosRay, out endPosHit, float.MaxValue, fieldLayer.value)) { Debug.LogError("did not hit field"); return; } Vector3 worldDirection = endPosHit.point - transform.position; //hit is at ground level, so make sure the ball doesn't move down worldDirection.y = 0; ballRigidbody.AddForce(pushPower * worldDirection.normalized); OnShoot?.Invoke(); alreadyShot = true; ballCanvas.Deactivate(); }
private void Handleshooting() { if (Input.GetMouseButtonDown(0)) { Vector3 mousePosition = UtilsClass.GetMouseWorldPosition(); ani.SetBool("shoot", true); OnShoot.Invoke(this, new OnShootEventArgs { gunEndPointPosition = aimGunEndPointTransform.position, shootPosition = mousePosition, }); } else { ani.SetBool("shoot", false); } if (Input.GetMouseButtonDown(1)) { isAimDownSights = !isAimDownSights; if (isAimDownSights) { newfieldofview.SetFoV(40f); newfieldofview.SetViewDistance(100f); } else { newfieldofview.SetFoV(90f); newfieldofview.SetViewDistance(50f); } } }
public static void Shoot() { if (!PlayerProfile.sounds) { return; } OnShoot.Invoke(); }
public void Shoot(bool isRight) { _lastShoot = Time.time; var bullet = GlobalPooler.Instance.GetBullet(bulletType).transform; bullet.position = shootingPoint.position; bullet.rotation = Quaternion.AngleAxis(isRight ? 0 : 180, Vector3.forward); OnShoot?.Invoke(); }
private void EvaluateEditorControl() { var horizontal = Input.GetAxis("Horizontal"); OnMove?.Invoke(horizontal); if (Input.GetKeyDown(KeyCode.UpArrow)) { OnShoot?.Invoke(); } }
public IShootable Shoot() { var res = gunClip?.Shoot(); if (res != null) { OnShoot?.Invoke(this, res); } return(res); }
// private void UpdateCrosshair(){ // crosshair.position = mousePosition; // } private void Shooting() { if (Input.GetMouseButtonDown(0)) { OnShoot?.Invoke(this, new OnShootEventArgs { gunEndPoint = gunPoint.position, shootPosition = mousePosition, }); } }
public void Shoot() { if (canShoot) { canShoot = !canShoot; GameObject go = ProjectilePool.Instance.GetInstance(muzzle.position, muzzle.rotation); go.layer = gameObject.layer; OnShoot?.Invoke(Muzzle.forward, Muzzle.position); Recoil(); } }
private void ShootProjectile() { GameObject projectile = Instantiate(rangedEnemyCharacterData.projectilePrefab, transform.position, Quaternion.identity); projectile.GetComponent <BaseProjectile>().ShootProjectile(target.position, rangedEnemyCharacterData.projectileSpeed, rangedEnemyCharacterData.damageAmount, rangedEnemyCharacterData.accuracy); if (OnShoot != null) { OnShoot.Invoke(); } }
private void Shoot() { if (OnShoot != null) { OnShoot.Invoke(); } BulletScript _bullet = Instantiate(bullet, shootingPoint.position, Quaternion.identity); _bullet.gameObject.SetActive(true); }
/// <summary> /// Creates projectile with current weapon at given position and with given rotation. /// </summary> /// <param name="position"></param> /// <param name="rotation"></param> /// <returns></returns> public bool Shoot(Vector2 position, float rotation) { if (_wasSqueezed == false && CanShootAtPosition(position)) { _wasSqueezed = true; var parameters = new ProjectileSpawnParameters(position, rotation, _settings.velocity, _settings.timeToLive, _modules, _inheritableModules, dummy: _info.IsLocal == false); Factory.Create(parameters); OnShoot?.Invoke(parameters); } return(true); }
protected void Shoot() { if (!_isReloaded) { return; } _pooler.GetPooledObject(_bullet.name, _barrel.position, _barrel.rotation); StartCoroutine(Reload()); OnShoot?.Invoke(); }
private void EvaluateTouchControl() { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { OnMove?.Invoke(Input.touches[0].deltaPosition.x); } if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) { OnShoot?.Invoke(); } }
private void HandleShooting() { if (Input.GetMouseButtonDown(0)) { Vector3 mousePosition = GetMousePos(); aimAnimator.SetTrigger("Shoot"); OnShoot?.Invoke(this, new OnShootEventArgs { gunEndPointPosition = aimGunEndPointTransform.position, shootPosition = mousePosition, }); } }
protected override void Attack() { if (dead) { return; } OnShoot?.Invoke(projectileSpeed, transform.position, (playerTransform.position - transform.position).normalized); anim.SetTrigger("Attacking"); audioManager.PlaySound(AudioManager.Sounds.EnemyProjectile); StartCoroutine(CoolDown()); }
private void HandleShooting() { if (Input.GetMouseButtonDown(0)) { Vector3 mousePosition = GetMouseWorldPosition(); // shootAnimator.SetBool("Shoot",true); OnShoot?.Invoke(this, new OnShootEventArgs { gunEndPointPosition = AimGunEndPointTransform.position, shootPosition = mousePosition, }); } }
private void HandleShoot() { if (Input.GetKeyDown(KeyCode.Mouse0)) { aimAnim.SetTrigger("shoot"); OnShoot?.Invoke(this, new OnShootEventArg { gunEndPoint = gunEndpointTransform.position, gunAimPoint = mousepos, meshLocation = meshLocationTransform.position, }); } }
private void HandleShooting() { if (Input.GetMouseButtonDown(0)) { animControl.isShooting(); OnShoot?.Invoke(this, new OnShootEventArgs { gunEndPointPosition = gunEndPointTransform.position, shootPosition = Utilities.GetMousePosition(), }); } }
// Update is called once per frame void Update() { if (active) { anim.ResetTrigger("Shoot"); aiming = Input.GetMouseButton(1); sprinting = !aiming && Input.GetButton("Sprint"); speedModifier = Input.GetMouseButton(1) ? aimModifier : (Input.GetButton("Sprint") ? sprintModifier : 1); movementVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); TranslateMovement(CameraForward(movementVector)); if (aiming) { gun.localPosition = aimGun; } else { gun.localPosition = walkGun; } if (movementVector != Vector3.zero) { anim.SetFloat("IdleWalk", 1f); Footsteps(); if (sprinting) { anim.SetFloat("WalkSprint", 1f); } else { anim.SetFloat("WalkSprint", 0f); } } else { anim.SetFloat("IdleWalk", 0f); } anim.SetBool("Aiming", aiming); if (Input.GetButtonDown("Fire1")) { if (OnShoot != null) { OnShoot.Invoke(); } anim.SetTrigger("Shoot"); } } }
private void UpdatePlayer(float axisUpDown, bool shoot) { player.MinX += time.DeltaTime * axisUpDown; //limit player position [left, right] player.MinX = MathHelper.Clamp(player.MinX, -1f, 1.0f - player.SizeX); if (shoot && !shootCoolDown.Enabled) { OnShoot?.Invoke(this, null); bullets.Add(new Box2D(player.MinX, player.MinY, 0.02f, 0.04f)); bullets.Add(new Box2D(player.MaxX, player.MinY, 0.02f, 0.04f)); shootCoolDown.Enabled = true; } }
public void AttackingEvent() { _attackCounter += Time.deltaTime; if (_attackCounter >= _attackSpeed) { _attackCounter = 0; if (EnemyGlobalListener.Instance.NearestEnemy != null) { OnShoot.Invoke(); } } }
private void UpdatePlayer(float absoluteTime, float timeDelta, float axisUpDown, bool shoot) { player.X += timeDelta * axisUpDown; //limit player position [left, right] player.X = Math.Min(1.0f - player.SizeX, Math.Max(-1.0f, player.X)); if (shoot && !shootCoolDown.Enabled) { OnShoot?.Invoke(this, null); bullets.Add(new Box2D(player.X, player.Y, 0.02f, 0.04f)); bullets.Add(new Box2D(player.MaxX, player.Y, 0.02f, 0.04f)); shootCoolDown.Start(absoluteTime); } }
private void Shoot() { var direction = Quaternion.EulerRotation(0, UnityEngine.Random.Range(-_spread, _spread), 0) * transform.forward; ShotData shotData = new ShotData(direction * _bulletSpeed * (AvatarController.Inverted ? -1 : 1)); var bullet = Instantiate(_bulletPrefab).GetComponent <Bullet>(); bullet.transform.position = transform.position; bullet.Initialize(shotData); if (OnShoot != null) { OnShoot.Invoke(shotData); } }
/// <summary> /// Applies weapon to whatever is ahead of player. /// </summary> private void UseWeapon(Weapon weapon) { if (isMelee) { // Currently, the hit sounds for melee weapons includes a swing sound as well in the same clip // so we're gonna check to see if there's a hit first and decide what clip to play from there. // AudioManager.PlayOneClip(audioSource, meleeWeapon.swings); } else { //make sure gun has ammoInClip if (ammoInClip == 0) { AudioManager.PlayOneClip(audioSource, rangedWeapon.dryShots); return; } AudioManager.PlayOneClip(audioSource, rangedWeapon.shots); ammoInClip = Math.Max(ammoInClip - 1, 0); OnShoot?.Invoke(); } int mask = LayerMask.GetMask("Enemies"); int xOffset = 5; RaycastHit2D[] hits = Physics2D.RaycastAll( transform.position + (Vector3.left * xOffset), Vector2.right, weapon.range + xOffset, mask); if (hits.Length > 0) { AudioManager.PlayOneClip(audioSource, isMelee ? meleeWeapon.hits : rangedWeapon.hits); int wounds = Math.Min(1 + weapon.ap, hits.Length); for (int i = 0; i < wounds; i++) { hits[i].collider.GetComponent <Enemy>().OnWounded?.Invoke(weapon.dmg); } } else { // Currently, the hit sounds for melee weapons includes a swing sound as well in the same clip // so we're gonna check to see if there's a hit first and decide what clip to play from there. if (isMelee) { AudioManager.PlayOneClip(audioSource, meleeWeapon.swings); } } }