public virtual void attack() { if (cooling) { return; } timer = cooldown; cooling = true; //anim.SetTrigger (this.shot); GameObject temp; if (!melee && (temp = Pool.shared.getobj(pooltype.muzzle))) //move to separate func, no need to repeat { temp.transform.position = gunpoint.position; temp.transform.rotation = transform.rotation; temp.SetActive(true); } //anim.SetTrigger (back2idle); Vector3 shot = (target.position + voff) + UnityEngine.Random.insideUnitSphere * margin; //cache vars shot -= gunpoint.position; RaycastHit hit; if (Physics.Raycast(gunpoint.position, shot, out hit, attrange)) { if (hit.transform.gameObject.layer == playerlayer) { //print ("shot"); player.damage(dmg); if (temp = Pool.shared.getobj(pooltype.blood)) { temp.transform.position = hit.point; temp.transform.rotation = Quaternion.LookRotation(hit.normal); temp.SetActive(true); } } else if (!melee) { if (temp = Pool.shared.getobj(pooltype.spark)) { temp.transform.position = hit.point; temp.transform.rotation = Quaternion.LookRotation(hit.normal); temp.SetActive(true); } if (temp = Pool.shared.getobj(pooltype.hole)) { temp.transform.position = hit.point; temp.transform.rotation = Quaternion.FromToRotation(Vector3.forward, hit.normal); temp.SetActive(true); } } } }