I am working on a project, where there will be nine weapons. These weapons will be activated once the kill count has reached a specific number. For this, I use bools for each weapon, and when the kill count reaches a specific number, the current weapon is set to false and the next is set to true. I then used “if” statements for each, so as to have unity instantiate a certain defined particle effect when the left click is held down. All that was logically possible, until I figured out that instead of one being instantiated, no matter which bool is marked “true”, all the nine particles are instantiated upon left-clicking. How did this occur? Can this be repaired?
Thanks in advance for your support!
MY CODE:
AllWeaponSystem.cs
using UnityEngine;
using System.Collections;
public class AllWeaponSystem : MonoBehaviour {
public GameObject Worm;
public GameObject Dazzler;
public GameObject Disaster;
public GameObject Grief;
public GameObject Creation;
public GameObject Corruption;
public GameObject Divinity;
public GameObject Plague;
public GameObject Addiction;
public bool hasWorm = true;
public bool hasDazzler = false;
public bool hasDisaster = false;
public bool hasGrief = false;
public bool hasCreation = false;
public bool hasCorruption = false;
public bool hasDivinity = false;
public bool hasPlague = false;
public bool hasAddiction = false;
public Transform WeaponFire;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
ClickToFire();
}
void ClickToFire() {
if(hasWorm = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Worm, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
if(hasDazzler = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Dazzler, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
if(hasDisaster = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Worm, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
if(hasGrief = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Grief, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
if(hasCreation = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Creation, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
if(hasCorruption = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Corruption, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
if(hasDivinity = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Divinity, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
if(hasPlague = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Plague, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
if(hasAddiction = true && Input.GetButtonDown("FireTrigger")) {
Instantiate(Addiction, WeaponFire.position, WeaponFire.rotation);
}
else {
return;
}
}
}
KillCount.cs
using UnityEngine;
using System.Collections;
public class killCount : AllWeaponSystem {
public int killCounter = 0;
void Update() {
weaponUpgrade();
}
void weaponUpgrade() {
AllWeaponSystem weapon = new AllWeaponSystem();
if(killCounter == 10) {
weapon.hasWorm = false;
weapon.hasDazzler = true;
}
if(killCounter == 20) {
weapon.hasDazzler = false;
weapon.hasDisaster = true;
}
if(killCounter == 35) {
weapon.hasDisaster = false;
weapon.hasGrief = true;
}
if(killCounter == 45) {
weapon.hasGrief = false;
weapon.hasCreation = true;
}
if(killCounter == 60) {
weapon.hasCreation = false;
weapon.hasCorruption = true;
}
if(killCounter == 75) {
weapon.hasCorruption = false;
weapon.hasDivinity = true;
}
if(killCounter == 99) {
weapon.hasDivinity = false;
weapon.hasPlague = true;
}
if(killCounter == 100) {
weapon.hasPlague = false;
weapon.hasAddiction = true;
}
}
}
EnemyHealth.cs
using UnityEngine;
using System.Collections;
public class enemyHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
void OnCollisionEnter(Collision weaponParticle) {
if(weaponParticle.gameObject.tag == "wormWeapon") {
curHealth -= 1;
}
if(weaponParticle.gameObject.tag == "dazzlerWeapon") {
curHealth -= 3;
}
if(weaponParticle.gameObject.tag == "disasterWeapon") {
curHealth -= 5;
}
if(weaponParticle.gameObject.tag == "griefWeapon") {
curHealth -= 9;
}
if(weaponParticle.gameObject.tag == "creationWeapon") {
curHealth -= 15;
}
if(weaponParticle.gameObject.tag == "corruptionWeapon") {
curHealth -= 20;
}
if(weaponParticle.gameObject.tag == "divinityWeapon") {
curHealth -= 25;
}
if(weaponParticle.gameObject.tag == "plagueWeapon") {
curHealth -= 28;
}
if(weaponParticle.gameObject.tag == "addictionWeapon") {
curHealth -= 30;
}
}
}