// SwitchToPrimary method void SwitchToPrimary(GameObject _Primary) { // Set Active (false) the current weapon if (weapon != null) { weapon.SetActive(false); } _PlayerShoot.CancelInvoke("Shoot"); weapon = _Primary.transform.GetChild(0).gameObject; weapon.SetActive(true); if (weapon.tag == "L96") { CrossHair.SetActive(false); } else { CrossHair.SetActive(true); } CurrentWeapon = PrimaryWeapon; _PlayerShoot.CurrentAmmo = _PlayerShoot.CurrentAmmoP; Primary = true; Secondery = false; currentGraphics = weapon.GetComponent <WeaponGraphics>(); _PlayerShoot.currentWeapon = CurrentWeapon; _PlayerShoot.weaponAnimation = currentGraphics.GetComponent <WeaponAnimation>(); }
private void FireWeapon() { RaycastHit hitInfo; Vector3 dir = camForShootRaycast.transform.forward + Random.insideUnitSphere * currentWeapon.accuracy; if (Physics.Raycast(camForShootRaycast.transform.position, dir, out hitInfo, currentWeapon.range, layerMask)) { if (hitInfo.collider.tag == "Player") { CmdPlayerWasShot(hitInfo.collider.name, currentWeapon.damage); } SpawnWeaponImpact(hitInfo.point, hitInfo.normal); } AudioClip clip = currentWeapon.singleShotSound; if (clip) { audioSource.clip = clip; audioSource.pitch = Random.Range(0.9f, 1.2f); audioSource.Play(); } WeaponGraphics gfx = weaponManager.GetCurrentGraphics(); gfx.TriggerVisualFireEffect(); //TODO: apply a recoil }
// need to complete void PickUpPrimary(GameObject _weapon) { if (weapon != null) { weapon.SetActive(false); } weapon = _weapon.transform.GetChild(0).gameObject; weapon.SetActive(true); if (weapon.tag == "L96") { CrossHair.SetActive(false); } else { CrossHair.SetActive(true); } PrimaryWeapon = weapon.GetComponent <WeaponGraphics>().weaponInfo; CurrentWeapon = PrimaryWeapon; Primary = true; Secondery = false; currentGraphics = weapon.GetComponent <WeaponGraphics>(); _PlayerShoot.currentWeapon = CurrentWeapon; _PlayerShoot.weaponAnimation = currentGraphics.GetComponent <WeaponAnimation>(); _PlayerShoot.CurrentAmmo = currentGraphics.AmmoStored; // updateAnimator.animator = _PlayerShoot.weaponAnimation.GetComponent<Animator>(); ////////////////////////////////////////////////// }
void RpcEquipWeapon(PlayerWeapon _curr, int index) { currWeapon = _curr; currGraphics = weaponObject[index].GetComponent <WeaponGraphics>(); SelectWeapon(index); currFirePoint = weaponObject[index].transform.Find("FirePoint"); }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; GameObject _weaponIns = Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); _weaponIns.transform.SetParent(weaponHolder, false); currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("No WeaponGraphics component on the weapon object: " + _weaponIns.name); } currentSounds = _weaponIns.GetComponent <WeaponSounds>(); if (currentSounds == null) { Debug.LogError("No WeaponSounds component on the weapon object: " + _weaponIns.name); } if (isLocalPlayer) { Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); } }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; //load weapon graphics GameObject _weaponIns = (GameObject)Instantiate(_weapon.wpnGraphics, weaponHolder.position, weaponHolder.rotation); //need to parent our weapon to our weaponholder so it follows us _weaponIns.transform.SetParent(weaponHolder); //look for the graphics component on our instance currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { currentGraphics = _weaponIns.GetComponentInChildren <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("No WeaponGraphics component on the weapon object: " + _weaponIns.name); } } if (isLocalPlayer) { //setting the weapon and all children of the parent to this layer in case our weapon is made of multiple objects Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); } }
private void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; if (_weaponIns != null) { Destroy(_weaponIns); } else { currentWeapon.currentAmmo = currentWeapon.maxCapacity; } _weaponIns = (GameObject)Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); _weaponIns.transform.SetParent(weaponHolder); currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("Missing WeaponGraphics script on weapon: " + _weaponIns.name); } if (isLocalPlayer) { Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); } }
void RpcDoShootEffect() //When one person Shoots, show visually to all clients { WeaponGraphics wg = wm.GetCurrentWeaponGraphics(); wg.weaponGFX.Play(); wg.anim.Play("ShootAnim"); }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; Vector3 _initialTransform = (weaponHolder.transform.position + _weapon.graphics.transform.position); weaponIns = (GameObject)Instantiate(_weapon.graphics, _initialTransform, transform.rotation); //Debug.Log(_weapon.graphics.transform.position); weaponIns.transform.SetParent(weaponHolder); Debug.Log(weaponIns.transform.position); currentGraphics = weaponIns.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("Current weapon has no graphics!" + weaponIns.name); } if (isLocalPlayer) { Util.SetLayerRecursively(weaponIns, LayerMask.NameToLayer(weaponLayerName)); } }
private void RpcEquipWeapon(int indexInWeapons) { //Debug.Log(transform.name + " Rpc Test: weapon.graphics is null " + (_weapon.graphics == null) + " weapon: [0].graphics is null " + (weapons[0].graphics == null)); if (currentWeapon != null && weaponsDic.ContainsKey(currentWeapon)) { //PutDown(); weaponsDic[currentWeapon].SetActive(false); } if (indexInWeapons >= weapons.Length && indexInWeapons < 0) { Debug.LogError(transform.name + " WeaponManager: indexInWeapons = " + indexInWeapons + " IndexOutOfRangeException."); } currentWeapon = weapons[indexInWeapons]; if (!weaponsDic.ContainsKey(currentWeapon)) { CreateWeapon(weapons[indexInWeapons]); } else { weaponsDic[currentWeapon].SetActive(true); currentGraphics = weaponsDic[currentWeapon].GetComponent <WeaponGraphics>(); } //PutOn(); }
public void EquipeWeapon(PlayerWeapon weapon) { Transform currentTransform = weapon.weaponGraphics.transform; currentWeapon = weapon; currentWeapon.weaponGraphics.transform.rotation = weaponHolder.rotation; currentWeapon.weaponGraphics.transform.position = weaponHolder.position; if (weaponHolder.childCount > 0) { Destroy(weaponHolder.GetChild(0).gameObject); } GameObject weaponInst = (GameObject)Instantiate(weapon.weaponGraphics, weaponHolder.position, weaponHolder.rotation); currentWeaponGraphics = weaponInst.GetComponent <WeaponGraphics>(); weaponInst.transform.SetParent(weaponHolder); currentWeaponGraphics = weaponInst.GetComponent <WeaponGraphics>(); Debug.Log("Rotation : " + currentWeaponGraphics.rotationX); weaponInst.transform.rotation = Quaternion.Euler(currentWeaponGraphics.rotationX, 0, 0); if (isLocalPlayer) { weaponInst.layer = LayerMask.NameToLayer(weaponLayerName); } if (isLocalPlayer) { Util.SetLayerRecursively(weaponInst, LayerMask.NameToLayer(weaponLayerName)); } }
void EquipWeapon(PlayerWeapon weapon) { _currentWeapon = weapon; GameObject weaponGlobalInst = (GameObject)Instantiate(weapon.graphics, _globalWeaponHolder.position, weapon.graphics.transform.rotation); weaponGlobalInst.transform.SetParent(_globalWeaponHolder); _currentGraphics = weaponGlobalInst.GetComponent <WeaponGraphics>(); if (isLocalPlayer) { GameObject weaponInst = (GameObject)Instantiate(weapon.graphics, _localWeaponHolder.position, weapon.graphics.transform.rotation); weaponInst.transform.SetParent(_localWeaponHolder); // Change the look locally weaponInst.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); weaponInst.transform.localPosition = new Vector3(0f, 0f, 0f); _currentGraphics = weaponInst.GetComponent <WeaponGraphics>(); if (_currentGraphics == null) { Debug.LogError("No graphics effects on weapon " + weaponInst.name); } weaponGlobalInst.layer = LayerMask.NameToLayer(_dontDrawLayerName); Util.SetLayerRecursively(weaponInst, LayerMask.NameToLayer(_weaponLayerName)); } }
void EquipWeapon(WeaponData _newWeapon) { currentWeapon = _newWeapon; GameObject _weaponIns = Instantiate(_newWeapon.graphics, weaponHolder); //_weaponIns.transform.localScale *= 1.5f; currentWeapon.SetAnim(_weaponIns.GetComponent <Animator>()); currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("No Weapon Graphics On the component on the weapon object: " + _weaponIns.name); } if (GetComponent <PhotonView>().isMine) { Debug.Log("Setting Local Graphics"); Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(LocalWeapon_LayerName)); } else { Debug.Log("Setting Remote Graphics"); Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(RemoteWeapon_LayerName)); } }
/// <summary> /// Instantiates weapon and sets graphics /// </summary> /// <param name="_weapon"></param> void EquipWeapon(Weapon weapon) { currentWeapon = weapon; if (weaponInstance) { Destroy(weaponInstance.gameObject); } weaponInstance = Instantiate(weapon.modelPrefab, rightGunBone); weaponInstance.transform.localPosition = Vector3.zero; weaponInstance.transform.localScale = weapon.modelPrefab.transform.localScale; weaponInstance.transform.localRotation = Quaternion.identity; GetComponent <Animator>().runtimeAnimatorController = controllerWithWeapon; // Set graphics if exists currentGraphics = weaponInstance.GetComponent <WeaponGraphics>(); if (!currentGraphics) { Debug.Log("No weapon graphics component on " + weaponInstance.name); } // Defines layer for local player if (isLocalPlayer) { weaponInstance.layer = LayerMask.NameToLayer(weaponLayerName); } }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; //ak GameObject _weaponIns2 = (GameObject)Instantiate(_weapon.graphics2, weaponHolder.position, weaponHolder.rotation); ak = _weaponIns2; _weaponIns2.transform.SetParent(weaponHolder); currentGraphics = _weaponIns2.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("No WeaponGraphics component on the weapon object: " + _weaponIns2.name); } if (isLocalPlayer) { Util.SetLayerRecursively(_weaponIns2, LayerMask.NameToLayer(weaponLayerName)); } //glock GameObject _weaponIns = (GameObject)Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); glock = _weaponIns; _weaponIns.transform.SetParent(weaponHolder); if (isLocalPlayer) { Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); } glock.SetActive(false); }
// Method to change the currentWeapon. void EquipWeapon(PlayerWeapon _weapon) { // Change the currentWeapon. currentWeapon = _weapon; // Instatiate the graphics for this weapon. GameObject _weaponIns = (GameObject)Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); // Make it a child of the WeaponHolder. _weaponIns.transform.SetParent(weaponHolder); // Find the weapon's graphics and store it. currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); // Check that the weapon we are using actually has graphics. if (currentWeapon == null) { // Throw error. Debug.LogError("WeaponManager: No WeaponGraphics component on the weapon object (" + _weaponIns.name + ")."); } // LocalPlayer's weapon has a special LayerMask. if (isLocalPlayer) { // Set the layer name recursively. Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); } }
void RpcHitEffect(Vector3 pos, Vector3 normal) { WeaponGraphics currentWeaponGraphics = weaponManager.GetCurrentGraphics(); GameObject impactEffect = Instantiate(currentWeaponGraphics.impactEffectPrefab, pos, Quaternion.LookRotation(normal)); Destroy(impactEffect, currentWeaponGraphics.impactEffectLiftime); }
private void Awake() { //装上一个弹夹 curAmmo = ammoPerClip; leftAmmo = maxAmmo - ammoPerClip; weaponGraphics = GetComponent <WeaponGraphics>(); bulletManager = GetComponent <BulletManager>(); mouseLook = Camera.main.GetComponent <MouseLook>(); }
//public Animator shotgunAnim; private void Start() { weapongraphics = this.GetComponent <WeaponGraphics>(); //shotgunAnim = GetComponent<Animator>(); Cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>(); GameObject player = GameObject.FindGameObjectWithTag("Player"); fpsController = player.GetComponent <FirstPersonController>(); }
private IEnumerator Relode(float r, float rt, WeaponGraphics g)//to call a method after a delay { //Destroy(g.magzinePrefab); yield return(new WaitForSeconds(rt));//change for different guns later. Mag = r; relodeGun?.Invoke(false); //RelodeInst.StopRelode(); CanShoot(true); }
void RpcDoSwitch2() { glock.SetActive(false); ak.SetActive(true); currentGraphics = ak.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("No WeaponGraphics component on the weapon object: " + ak.name); } }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; GameObject _weaponIns = (GameObject)Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); _weaponIns.transform.SetParent(weaponHolder); currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); }
IEnumerator DoShootEffectCoroutine() { weaponManager.GetCurrentSounds().PlayShotSound(); WeaponGraphics weaponGraphics = weaponManager.GetCurrentGraphics(); weaponGraphics.muzzleFlash.Play(); weaponGraphics.laserRendered.enabled = true; yield return(new WaitForSeconds(weaponGraphics.laserTime)); weaponGraphics.laserRendered.enabled = false; }
private void EquipWeapon(PlayerWeapon weapon) { this._currentWeapon = weapon; GameObject weaponIns = (GameObject)Instantiate(weapon.Graphics, this._weaponHolder.position, this._weaponHolder.rotation); weaponIns.transform.SetParent(this._weaponHolder); this._currentGraphics = weaponIns.GetComponent<WeaponGraphics>(); if (this._currentGraphics == null) Debug.LogError("No WeaponGraphics component at the weapon object: " + weaponIns.name); if (this.isLocalPlayer) Util.SetLayerRecursively(weaponIns, LayerMask.NameToLayer(this._weaponLayerName)); }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; GameObject _weaponIns = (GameObject)Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); _weaponIns.transform.SetParent(weaponHolder); currentGraphics = _weaponIns.GetComponent<WeaponGraphics>(); if (currentGraphics == null) Debug.LogError("No WeaponGraphics component on the weapon object: " + _weaponIns.name); if (isLocalPlayer) Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; GameObject _weaponInstance = (GameObject)Instantiate(_weapon.weaponModel, weaponHolder.position, weaponHolder.rotation); _weaponInstance.transform.SetParent(weaponHolder); currentGraphics = _weaponInstance.GetComponent <WeaponGraphics> (); if (currentGraphics == null) { Debug.LogError("WeaponMannager: No Weapon Graphic Found in weapon object " + _weaponInstance.name); } Util.SetLayerRecursively(_weaponInstance, LayerMask.NameToLayer(weaponLayerName)); }
private void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; _weaponIns = (GameObject)Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); _weaponIns.transform.SetParent(weaponHolder); currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (isLocalPlayer) { Utility.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer("Weapon")); } }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; GameObject _weaponIns = (GameObject)Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); _weaponIns.transform.SetParent(weaponHolder); currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("No WeaponGraphics component on the weapon object: " + _weaponIns.name); } }
void RpcDropWeapon() { if (currentWeapon != null) { currentWeapon = null; currentGraphics = null; currentWeaponPickup.gameObject.SetActive(true); currentWeaponPickup.transform.position = transform.position + transform.forward; Quaternion newRotation = Quaternion.LookRotation(transform.forward) * Quaternion.Euler(-90, 0, 0); currentWeaponPickup.transform.rotation = newRotation; GetComponent <PlayerShoot>().CancelInvoke("Shoot"); GetComponent <Animator>().runtimeAnimatorController = controllerWithoutWeapon; Destroy(weaponInstance.gameObject); } }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; GameObject _weaponIns = (GameObject)Instantiate(_weapon.weaponGraphics, weaponHolder); currentWeaponGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (currentWeaponGraphics == null) { Debug.Log("No weapon graphics on weapon :: " + _weaponIns.name); } if (isLocalPlayer) { Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); } }
private void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; GameObject _weaponIns = Instantiate <GameObject>(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); _weaponIns.transform.SetParent(weaponHolder); currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.Log("No WeaponGraphics on current weapon: " + _weaponIns.name); } if (isLocalPlayer) { Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); } }
void Shoot() { audio.Play(); WeaponGraphics currentGraphics = GetComponent <WeaponGraphics>(); muzzleflash.Play(); RaycastHit hit; if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, weapon.range, mask)) { if (hit.collider.tag == "Player") { CmdPlayerShot(hit.collider.name, weapon.damage); } } }