//Update, means normal Update method private void Update() { //Debug.Log("FULL AUTO: " + fullAutoMode); if (fullAutoMode == false) { timeSinceLastAttack += Time.deltaTime; return; } else { if (Input.GetButton("Fire1") && timeSinceLastAttack > attackDelay) { timeSinceLastAttack = 0f; //Yeah, I know this is kinda of a hacky solution to my own solution, //but I guess this works... Is this what people call emergent design? GameObject target = baseRaycastShooter.GetTargetByRaycast(); if (target != null) { baseRaycastShooter.DamageTarget(target); } } timeSinceLastAttack += Time.deltaTime; } }
//Component On Invoked will be called by the left click button, only when it //is marked with the 'Base' weapon component type. public override void ComponentOnInvoked() { //Fire raycast: GameObject target = raycastShooter.GetTargetByRaycast(); bool doSpawn = false; //Damage the target if (target != null) { Health healthComponent = target.GetComponent <Health>(); if (healthComponent) { //Determine whether the enemy hit would die from the attack: if ((healthComponent.currentHealth - raycastShooter.damageAmount) <= 0f) { //If yes, then set this local bool to true, doSpawn = true; } else { //if not then false. doSpawn = false; } healthComponent.DealDamage(raycastShooter.damageAmount); } } bool successfulRoll = Random.value <= dropChances; if (doSpawn && successfulRoll) { //Spawn ammo drop at the position of the thing that was hit: Instantiate(ammoPickupPrefab, target.transform.position, Quaternion.identity); } }