void PrimaryAndPowerInputCheckAndUse(int mouseInput, WeaponsHolder holder) { if (!isAttaching && !isDetaching && controller.IsMineAndAlive()) { Weapon weapon = holder.weaponAttached; if (weapon && (weapon.weaponType != WeaponType.Primary || (weapon.weaponType == WeaponType.Primary && !isChangingBehaviour))) { bool buttonPressed = false; int behaviourIndex = weapon.GetBehaviourIndex(weapon); switch (weapon.weaponBehaviours[behaviourIndex].attackType) { case AttackType.Automatic: if (Input.GetMouseButton(mouseInput)) { buttonPressed = true; } break; case AttackType.SemiAutomatic: if (Input.GetMouseButtonDown(mouseInput)) { buttonPressed = true; } break; } if (buttonPressed) { weapon.Use(); } } } }
public void AttachDetachWeapon(Weapon weapon, bool useAnimDelay, bool allowDetach) { if (!isAttaching && !isDetaching) { WeaponsHolder holder = GetHolder(weapon.weaponType); StartCoroutine(CheckForAndSetAttached(holder, weapon, useAnimDelay, allowDetach)); } }
private void Start() { minEyeScale = eye.transform.localScale * minEyeScaleSize; maxEyeScale = eye.transform.localScale * maxEyeScaleSize; moving = false; waitTime = 4f; waitTimer = 0.1f; weapons = GetComponentInChildren <WeaponsHolder>(); }
// Start is called before the first frame update void Start() { surfaceTimer = surfaceTime; burrowTimer = 0; travelTimer = 0; riseTimer = 0; weapons = GetComponentInChildren <WeaponsHolder>(); burrowParticles.GetComponent <ParticleSystem>().Stop(); risingParticles.Stop(); surfaceParticles.Play(); camera = Camera.main; }
void Start() { inventoryWeapons = CurrentPlayer.Inventory.Weapons; inventoryAmmo = CurrentPlayer.Inventory.Ammo; // init weapons Weapon[] ws = GetComponentsInChildren <Weapon>(true); weapons = new Dictionary <WeaponIndex, Weapon>(); foreach (Weapon w in ws) { // scene's weapon index is not set // so parse it WeaponIndex index = (WeaponIndex)Enum.Parse(typeof(WeaponIndex), w.gameObject.name); // include it only if available in inventory // if (inventoryWeapons.IsAvailable(index)) { weapons.Add(index, w); w.Init(this, inventoryWeapons.Get(index), inventoryAmmo); } } // get audio sources audioSources = GetComponentsInChildren <AudioSource>(); audioSourceIndex = 0; Debug.Assert(audioSources.Length != 0, "No audio source for weapons"); // animation commonAnimation = GetComponent <Animation>(); Debug.Assert(commonAnimation != null); // states isSwitching = false; canSwitchToAnotherNext = false; currentWeapon = new Maybe <WeaponIndex>(); nextWeapon = new Maybe <WeaponIndex>(); // events SignToEvents(); // set parameters for weapons particles InitParticles(); // to default Reinit(); isInitialized = true; }
IEnumerator Attach(WeaponsHolder holder, Weapon weapon, bool useAnimDelay) { if (weapon) { isAttaching = true; weapon.Attach(holder.weaponsHolder); holder.animator.speed = animationSpeed; holder.animator.SetTrigger("ScrewOn"); if (useAnimDelay) { yield return(new WaitForSeconds(holder.timeToAttach)); } } holder.weaponAttached = weapon; isAttaching = false; }
public WeaponsHolder GetHolder(WeaponType type) { WeaponsHolder holder = new WeaponsHolder(); switch (type) { case WeaponType.Primary: holder = primaryWeaponsHolder; break; case WeaponType.Power: holder = powerWeaponsHolder; break; } return(holder); }
IEnumerator Detach(WeaponsHolder holder, bool useAnim) { print("Detach"); isDetaching = true; if (useAnim) { holder.animator.speed = animationSpeed; holder.animator.SetTrigger("ScrewOff"); yield return(new WaitForSeconds(holder.timeToDetach)); } if (controller.IsMineCheck()) { Tools.SetLocalOrGlobalLayers(holder.weaponAttached.meshObjects.ToArray(), true); } holder.weaponAttached.transform.SetParent(null); holder.weaponAttached.ResetPosAndRot(); holder.weaponAttached.interactingController = null; holder.weaponAttached = null; isDetaching = false; }
IEnumerator CheckForAndSetAttached(WeaponsHolder holder, Weapon weapon, bool useAnimDelay, bool allowDetach) { if (!isAttaching && !isDetaching) { float extraAttachWaitTime = 0f; if (holder.weaponAttached && allowDetach) { extraAttachWaitTime = holder.timeToDetach; animationSpeed = 1 / holder.timeToDetach; StartCoroutine(Detach(holder, useAnimDelay)); } if (controller.IsMineCheck()) { Tools.SetLocalOrGlobalLayers(weapon.meshObjects.ToArray(), false); } if (useAnimDelay) { yield return(new WaitForSeconds(extraAttachWaitTime)); } animationSpeed = 1 / holder.timeToAttach; StartCoroutine(Attach(holder, weapon, useAnimDelay)); } }