public void Fire(Transform cameraPoint) { #if DEBUG if (m_BulletBehaviourScripts.Count == 0) { Debug.LogWarning("GunTemplate::Fire(): No bollit in clip!"); return; } #endif if (m_TimePastSinceLastFire >= m_Rpm) { Ray ray = new Ray(cameraPoint.position, cameraPoint.forward); Vector3 raycastedDir = cameraPoint.forward; if (Physics.Raycast(ray, out m_RaycastHit, m_RayMaxDist)) { raycastedDir = (m_RaycastHit.point - m_BulletSpawnPoint.position).normalized; } BulletBehaviour bulletScr = m_BulletBehaviourScripts[m_NextFreeBullet]; GameObject bulletClone = m_BulletPrefabClones[m_NextFreeBullet]; bulletScr.Fire(m_BulletSpawnPoint, raycastedDir); m_BulletBehaviourScripts.Remove(bulletScr); m_BulletPrefabClones.Remove(bulletClone); if (m_NextFreeBullet == 0) { return; } --m_NextFreeBullet; m_TimePastSinceLastFire = 0.0f; } }
public override void Fire() { RaycastHit hitInfo; int layerMask = ~(1 << 5); BulletBehaviour b = bulletPool.Create(Player, 0, MuzzleTrans.position) as BulletBehaviour; if (Physics.Raycast(Player.transform.position, Player.transform.forward, out hitInfo, 1000, layerMask)) { //Debug.Log("hitting: " + hitInfo.collider.gameObject.ToString()); b.TargetPos = hitInfo.point; } else { b.TargetPos = MuzzleTrans.position + this.transform.parent.forward; } if (this.effect != null) { b.Effect = this.effect; if (this.effect.hasColor) { this.effect.SetTargetColor(b.gameObject); } } b.Fire(); base.Fire(); }
void CmdFire(Vector3 position, Quaternion rotation, string id, string name) { GameObject obj = _spawnManager.GetFromPool(); BulletBehaviour bullet = obj.GetComponent <BulletBehaviour> (); bullet.Fire(id, name, position, rotation); NetworkServer.Spawn(obj, _spawnManager.assetId); }
// FixedUpdate is called every physics tick void FixedUpdate() { float percent = playerInput.CurrentInput.MoveDir.magnitude; if (playerInput.CurrentInput.MoveDir.magnitude > 0) { percent = energyManager.SpendThrustEnergy(percent); } /* movement handling */ if (playerInput.CurrentInput.MoveDir == Vector2.zero) { // decelerate if no input rb.velocity *= 1 - decelerationPerTick; } else { rb.AddForce(playerInput.CurrentInput.MoveDir * thrust * percent); // clamp velocity to max speed rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxControlledVelocity); } /* weapon handling */ if (fire1 && Time.time >= (time + fireWait)) { if (energyManager.SpendBulletEnergy()) { gunSoundSource.Play(); Poolable obj = bulletPool.Pop(); BulletBehaviour bullet = obj.GetComponent <BulletBehaviour>(); // sin and cosine for current aim direction float sin = Mathf.Sin(rb.rotation * Mathf.Deg2Rad); float cos = Mathf.Cos(rb.rotation * Mathf.Deg2Rad); // find offset for gun barrel Vector2 b = barrels[barrelNum]; Vector2 offset = new Vector2(b.x * cos - b.y * sin, b.x * sin + b.y * cos); if (++barrelNum >= barrels.Length) { barrelNum = 0; } // fire bullet from offset position bullet.transform.position = rb.position + offset; bullet.Fire(aimDir); time = Time.time; } // reset input bool fire1 = false; } }
void Shoot() { BulletBehaviour newBullet = bulletPool.GetObjectFromPool(); newBullet.transform.SetPositionAndRotation(cannonTransform.position, cannonTransform.rotation); // TODO: apply ship velocity to bullet? newBullet.Fire(Vector3.zero, bulletLayerId); newBullet.gameObject.SetActive(true); }
protected virtual void SpawnProjectile(Step step) { ProjectilePrefab projectile = ProjectilePrefabs[step.projectile.code]; GameObject inst = Instantiate(projectile.prefab, transform.position + transform.TransformDirection(projectile.offset), transform.rotation); // 임시 BulletBehaviour bullet = inst.GetComponent <BulletBehaviour>(); bullet.Fire(projectile.speed, projectile.lifeTime); stepStarted = false; stepFinished = true; }
private void SpawnNewBullets(int energyAmount) { float yRot = Random.Range(0, 360); for (int i = 0; i < energyAmount; i++) { GameObject newBullet = Instantiate(_bulletPrefab, transform.position, Quaternion.Euler(new Vector3(0, yRot + 360 / (i + 1), 0))); BulletBehaviour bulletBehaviour = newBullet.GetComponent <BulletBehaviour>(); bulletBehaviour.SetDamageAmount(1); bulletBehaviour.Fire(_distanceToChildrenBullets, _ownerId); newBullet.transform.localScale = Vector3.one; } SetDamageAmount(1); Destroy(gameObject); }
private void CountDownAndShoot() { Timer -= Time.deltaTime; if (Timer <= 0) { behaviour.Fire(gameObject.transform); BulletSourceEvent.Invoke(); if (positionInShotSequence == behaviour.shotDelaySequence.Length - 1) { positionInShotSequence = 0; } else { positionInShotSequence++; } Timer = behaviour.shotDelaySequence[positionInShotSequence]; } }
private void Shoot(GameObject bulletPrefab, float holdTime, int bulletDamage) { SoundManager.Instance.PlaySomeAudio("Shoot"); GameObject bullet = Instantiate(bulletPrefab, _shootSpawner.transform.position, transform.rotation); bullet.GetComponent <BulletBehaviour>().SetDamageAmount(bulletDamage); _bulletDistance = Mathf.Lerp(_minBulletDistance, _maxBulletDistance, Mathf.InverseLerp(0, _maxForceToShoot, holdTime)); BulletBehaviour bulletBehaviour = bullet.GetComponent <BulletBehaviour>(); bulletBehaviour.Fire(_bulletDistance, (int)_playerController.Index); _playerAnimController.Shoot(); #pragma warning disable CS0618 // O tipo ou membro é obsoleto ChargingParticle.startSize = 0f; ChargingParticle.Clear(); #pragma warning restore CS0618 // O tipo ou membro é obsoleto }