// Start is called before the first frame update void Start() { gunScriptLastFrame = getCorrectGunScript(); UpdateUsedGun(currentGunScript != null); onStart.Invoke(gunScriptLastFrame.GetAmmo(), gunScriptLastFrame.GetClipSize(), gunScriptLastFrame.GetRemainingClips(), gunScriptLastFrame.GetAutoFire()); }
public void setGunScript(weaponController gun) { currentGunScript = gun; currentGunScript.transform.localRotation = Quaternion.Euler(Vector3.zero); if (rotateWeapon) { ChangeWeaponDirection(); } }
void Start() { whL = transform.DeepFind("weaponHandleL").gameObject; whR = transform.DeepFind("weaponHandleR").gameObject; wcL = BindWeaponController(whL); wcR = BindWeaponController(whR); weaponColL = whL.GetComponentInChildren <Collider>(); weaponColR = whR.GetComponentInChildren <Collider>(); weaponDisable(); //print(transform.DeepFind("weaponHandleR")); }
private void OnTriggerStay2D(Collider2D other) { if (Input.GetKeyDown("e")) //pickup button { weaponController old_weapon = other.gameObject.GetComponent <weaponSheath>().equiped_weapon.GetComponent <weaponController>(); if (old_weapon != null) //if the owner had a previous item, drop that item { old_weapon.set_drop_mode(); } gameObject.transform.parent.GetComponent <weaponController>().set_pickup_mode(other.gameObject); } }
void OnTriggerEnter(Collider col) { weaponController targetWc = col.GetComponentInParent <weaponController>(); GameObject attacker = targetWc.wm.am.gameObject; GameObject receiver = am.gameObject; Vector3 attackingDir = receiver.transform.position - attacker.transform.position; float attackingAngle1 = Vector3.Angle(attacker.transform.forward, attackingDir); if (attackingAngle1 <= 45) { if (gameObject.name == "sensor") { if (col.tag == "bossWeapon") { am.TryDoDamage(bossDmg); } else if (col.tag == "normalWeapon") { am.TryDoDamage(normalDmg); } else if (col.tag == "advancedWeapon") { am.TryDoDamage(advanceDmg); } else if (col.tag == "invisibleWeapon") { am.TryDoDamage(invisibleDmg); } } else if (gameObject.name == "npcSensor") { if (col.tag == "playerWeapon") { am.TryDoDamage(playerDmg); } } } }
public void UpdateUsedGun(bool hasSpecialGun) { if (hasSpecialGun) { defaultGunScript.gameObject.SetActive(false); currentGunScript.gameObject.SetActive(true); } else { defaultGunScript.gameObject.SetActive(true); if (currentGunScript != null) { Destroy(currentGunScript.gameObject); } } weaponController temp = getCorrectGunScript(); onSwapWeapon.Invoke(temp.GetAmmo(), temp.GetClipSize(), temp.GetRemainingClips(), temp.GetAutoFire()); GetComponent <ReloadBar>().EndReload(); }
protected void PickUp(Transform whom) { string tag = whom.tag; if (tag == "AI" || tag == "Player") { if (tag == "AI") { transform.parent = whom.Find("weapons"); } else { transform.parent = whom.Find("Camera/weapons"); } wC = whom.GetComponent <weaponController>(); wC.newWeapon(gameObject); Destroy(GetComponent <BoxCollider>()); dropText.text = ""; } }
public void modHp(float deltaHp) { if (_glitchValue != null) { _glitchValue.modGlitch(deltaHp); } currentHealth += deltaHp; if (deltaHp < 0) //if the entity is losing health, play damage particles { hit_particle.Play(); } if (currentHealth <= 0) { //drop weapon if any weaponSheath sheath = gameObject.GetComponent <weaponSheath>(); if (sheath != null) //dont assume all entities will have a weapon sheath { weaponController old_weapon = sheath.equiped_weapon.GetComponent <weaponController>(); if (old_weapon != null) { old_weapon.set_drop_mode(); } } for (int i = 0; i < Random.Range(2, 6); i++) //drop some coins //ALSO RANDOMIZE POSITION { Instantiate(Resources.Load("gold_coin"), transform.position, transform.rotation); } Destroy(this.gameObject); //THIS IS VERY BAD, especially for players, fix later } else if (currentHealth > baseHealth) { currentHealth = baseHealth; } //cant go over max hp }
public GameObject EquipWeapon(GameObject prefab) { GameObject.Destroy(curWpn); GameObject newWpn = GameObject.Instantiate(prefab, HandBone); weaponComp = newWpn.GetComponent <weaponController>(); thisAnimator.SetBool("twoHanded", weaponComp.twoHanded); thisAnimator.SetBool("thrust", weaponComp.thrust); melee = weaponComp.melee || weaponComp.deployable; thisAnimator.SetBool("noTrace", weaponComp.melee || weaponComp.thrown || weaponComp.deployable); thisAnimator.SetBool("deploy", weaponComp.deployable); thisAnimator.SetBool("thrown", weaponComp.thrown); /*if (!weaponComp.melee && weaponComp.twoHanded) * thisAnimator.SetFloat("rifle", 1f); * else * * thisAnimator.SetFloat("rifle", 0f); */ thisAnimator.SetFloat("variant", weaponComp.variant); GameValues.setGui(weaponComp.icon, weaponComp.cost, actionPts, weaponComp.name); return(newWpn); }
void Start() { weapon_control = gameObject.GetComponent <weaponController>(); }
// Update is called once per frame void Update() { weaponController gunScript = getCorrectGunScript(); currentGunCd -= Time.deltaTime; bool autoFire = gunScript.GetAutoFire(); if (((!autoFire && Input.GetButtonDown(specs.FireButtonName())) || (autoFire && Input.GetButton(specs.FireButtonName()))) && currentGunCd <= 0f) { GetComponent <ReloadBar>().EndReload(); bool result; gunScript.ShootBullet(); if (gunScript.GetAmmo() == 1) { currentGunCd = gunScript.GetMaxReloadCd(); GetComponent <ReloadBar>().StartReloading(); GameObject.Find("/Audio Objects/SFX/Reload").GetComponent <AudioSource>().Play(); } else { currentGunCd = gunScript.GetMaxCd(); } if (gunScript) { result = gunScript.SubtractAmmo(); if (!result) { Destroy(gunScript.gameObject); } weaponController temp = getCorrectGunScript(); if (temp == defaultGunScript) { onShootingEvent.Invoke(temp.GetAmmo() % temp.GetClipSize(), temp.GetClipSize(), -1, autoFire); } else { onShootingEvent.Invoke(temp.GetAmmo() % temp.GetClipSize(), temp.GetClipSize(), temp.GetRemainingClips(), autoFire); } } } if (gunScript != gunScriptLastFrame) { weaponController temp = getCorrectGunScript(); if (gunScript == defaultGunScript) { UpdateUsedGun(false); //onSwapWeapon.Invoke(temp.GetAmmo(), temp.GetClipSize(), -1, temp.GetAutoFire()); } else { UpdateUsedGun(true); //onSwapWeapon.Invoke(temp.GetAmmo(), temp.GetClipSize(), temp.GetRemainingClips(), temp.GetAutoFire()); } } weaponController tmp = getCorrectGunScript(); if (currentGunCd > -Time.deltaTime && currentGunCd < 0f && tmp.GetAmmo() == tmp.GetClipSize()) { GetComponent <ReloadBar>().EndReload(); onEndReload.Invoke(tmp.GetAmmo(), tmp.GetClipSize(), tmp.GetRemainingClips(), tmp.GetAutoFire()); } gunScriptLastFrame = getCorrectGunScript(); }