Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void InitializeGun()
- {
- print("InitializeGun");
- if (Gun == null) { Debug.Log("Oh, i dont have a Gun."); return; }
- if (AudioSource == null) { _audioSource = this.GetComponent<AudioSource>(); }
- if (MainCamera == null) { MainCamera = Camera.main; }
- cachedSocketPosition = gunSocket.transform.localPosition;
- if (photonView.isMine)
- {
- Gun.Set(this.gameObject);
- Gun.Initialize(null); //call Initialize from WeaponBase/GunBase class
- }
- else
- {
- WeaponType = Gun.WeaponType;
- GunName = Gun.WeaponName;
- Description = Gun.Description;
- FireSound = Gun.UseSound;
- _audioSource.clip = FireSound;
- ReloadSound = Gun.ReloadSound;
- HitEffect = Gun.HitEffect;
- }
- if (GunObject == null)
- {
- GunObject = PhotonNetwork.Instantiate(Gun.ResourcesPath, new Vector3(0, 0, 0), Quaternion.identity, 0); //Creating the Gun and parent it to the Socket in localSpace
- //photonView.ObservedComponents.Add(GunObject.transform);
- GunObject.transform.SetParent(gunSocket.transform, false);
- GunObject.transform.localPosition = Gun.PositionOffset; //use Position we made in the Scriptable WeaponBase
- }
- if (Gun.MuzzleFlash == null)
- {
- Debug.Log(GunName + " has no muzzleFlash.");
- }
- else
- {
- //MuzzleFlash = Instantiate(Gun.MuzzleFlash, GunObject.transform, false);
- var t = PhotonNetwork.Instantiate(Gun.MuzzleFlashPath, new Vector3(0, 0, 0), Quaternion.identity, 0);
- t.transform.SetParent(GunObject.transform, false);
- MuzzleFlash = t.GetComponent<ParticleSystem>();
- MuzzleFlash.transform.localPosition = Gun.MuzzleFlashPosition; //using a offset to well place the MuzzleFlash
- MuzzleFlash.transform.rotation = Quaternion.LookRotation(GunObject.transform.forward, GunObject.transform.up); //TODO simplify
- }
- if (Gun.WeaponType == GunTypes.Thrower) //If the GunType is Thrower we have to setup some more Things
- {
- AudioSource.clip = FireSound;
- AudioSource.loop = true; //the Sound should always Play if the Button is down
- }
- SetupObjectPool();
- }
- private void SetupObjectPool()
- {
- if (HitEffect == null && Gun.WeaponType != GunTypes.Thrower) { Debug.LogError("No HitEffect attached."); }
- projectileHolder = new GameObject("ProjectilePool").transform;
- hiteffectHolder = new GameObject("HiteffectPool").transform;
- if (WeaponType == GunTypes.HeavyGun)
- {
- ProjectileBehaviour pb = Gun.Projectile.GetComponent<ProjectileBehaviour>();
- float lifeTime = pb.LifeTime;
- float poolSize = ((1 / Gun.FireRate) * lifeTime) * Gun.ProjectileCount;
- t_Pool.CreateNewPool(Gun.Projectile,Gun.ProjectilePath, (int)poolSize, projectileHolder);
- }
- if (WeaponType != GunTypes.Thrower && WeaponType != GunTypes.HeavyGun)
- {
- float poolSize = ((1 / Gun.FireRate) * 1);
- t_Pool.CreateNewPool(Gun.HitEffect.gameObject,Gun.HitEffectPath, (int)poolSize, hiteffectHolder);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement