void Start() { if (!GameDamageDirector.AllowRayShoot) { GameObjectHelper.DestroyGameObject(gameObject); return; } trail = this.gameObject.GetComponent <LineRenderer>(); RaycastHit hit; GameObject explosion = null; if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, Range)) { AimPoint = hit.point; if (Explosion != null) { explosion = GameObjectHelper.CreateGameObject( Explosion, AimPoint, this.transform.rotation, true); } } else { AimPoint = this.transform.forward * Range; explosion = GameObjectHelper.CreateGameObject( Explosion, AimPoint, this.transform.rotation, true); } if (explosion) { GameDamageBase dmg = explosion.GetComponent <GameDamageBase>(); if (dmg) { dmg.TargetTag = TargetTag; } } if (trail) { trail.SetPosition(0, this.transform.position); trail.SetPosition(1, AimPoint); } GameObjectHelper.DestroyGameObject(this.gameObject, LifeTime); }
public void Shoot() { if (InfinityAmmo) { Ammo = 1; } if (Ammo > 0) { if (Time.time > nextFireTime + FireRate) { nextFireTime = Time.time; torqueTemp = TorqueSpeedAxis; Ammo -= 1; Vector3 missileposition = this.transform.position; Quaternion missilerotate = this.transform.rotation; if (MissileOuter.Length > 0) { missilerotate = MissileOuter[currentOuter].transform.rotation; missileposition = MissileOuter[currentOuter].transform.position; } if (MissileOuter.Length > 0) { currentOuter += 1; if (currentOuter >= MissileOuter.Length) { currentOuter = 0; } } if (Muzzle) { GameObject muzzle = GameObjectHelper.CreateGameObject( Muzzle, missileposition, missilerotate, true); muzzle.transform.parent = this.transform; GameObjectHelper.DestroyGameObject(muzzle, MuzzleLifeTime); if (MissileOuter.Length > 0) { muzzle.transform.parent = MissileOuter[currentOuter].transform; } } for (int i = 0; i < NumBullet; i++) { if (Missile) { Vector3 spread = new Vector3( Random.Range(-Spread, Spread), Random.Range(-Spread, Spread), Random.Range(-Spread, Spread)) / 100; Vector3 direction = this.transform.forward + spread; GameObject bullet = GameObjectHelper.CreateGameObject( Missile, missileposition, missilerotate, true); NameEffect(bullet); GameDamageBase damageBase = bullet.GetComponent <GameDamageBase>(); if (damageBase) { damageBase.gamePlayerController = gamePlayerController; damageBase.TargetTag = TargetTag; } GameWeaponBase weaponBase = bullet.GetComponent <GameWeaponBase>(); if (weaponBase) { weaponBase.gamePlayerController = gamePlayerController; weaponBase.Target = target; weaponBase.TargetTag = TargetTag; } bullet.transform.forward = direction; if (RigidbodyProjectile) { if (bullet.Has <Rigidbody>()) { Rigidbody rigid = bullet.Get <Rigidbody>(); if (rigid != null) { if (gamePlayerController != null && gamePlayerController.gameObject.GetRigidbody()) { rigid.velocity = gamePlayerController.gameObject.GetRigidbody().velocity; } rigid.AddForce(direction * ForceShoot); } } } } } if (!FPSDisplay.isUnder25FPS && Shell) { Transform shelloutpos = this.transform; if (ShellOuter.Length > 0) { shelloutpos = ShellOuter[currentOuter]; } GameObject shell = GameObjectHelper.CreateGameObject( Shell, shelloutpos.position, Random.rotation, true); GameObjectHelper.DestroyGameObject(shell.gameObject, ShellLifeTime); if (shell.Has <Rigidbody>()) { shell.Get <Rigidbody>().AddForce(shelloutpos.forward * ShellOutForce); } } if (SoundGun.Length > 0) { if (audio) { audio.volume = (float)GameProfiles.Current.GetAudioEffectsVolume(); audio.PlayOneShot(SoundGun[Random.Range(0, SoundGun.Length)]); } } nextFireTime += FireRate; } } }