public void SuckemUp() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit)) { Debug.Log(hit.transform.name); DustEnemyScript target = hit.transform.GetComponent <DustEnemyScript>(); StainEnemyScript target2 = hit.transform.GetComponent <StainEnemyScript>(); GermEnemyScript target3 = hit.transform.GetComponent <GermEnemyScript>(); //TEMP: Get targets gameobject to test if wrong weapon used GameObject targetGO = hit.transform.gameObject; if (target != null && target.tag == "RedEnemy") { target.transform.position = Vector3.MoveTowards(target.transform.position, transform.position, 0.8f); //TEMP: Notify on wrong weapon used } if (target3 != null && target3.tag == "BlueEnemy") { target3.transform.position = Vector3.MoveTowards(target3.transform.position, transform.position, 0.8f); } if (targetGO != null && targetGO.tag == "BlueEnemy") { StartCoroutine("WrongWeaponNotify"); } } }
//swing function, works in the same way as the shoot function, instead looking for "Red Enemy". public void Swing() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, 150)) { Debug.Log(hit.transform.name); DustEnemyScript target = hit.transform.GetComponent <DustEnemyScript>(); StainEnemyScript target2 = hit.transform.GetComponent <StainEnemyScript>(); //TEMP: Get targets gameobject to test if wrong weapon used GameObject targetGO = hit.transform.gameObject; if (target != null && target.tag == "RedEnemy") { staticForce += 1; swingHit = true; //TEMP: Notify on wrong weapon used } if (targetGO != null && targetGO.tag == "BlueEnemy") { StartCoroutine("WrongWeaponNotify"); } if (target2 != null && target2.tag == "Stain Enemy" && target2.stainHealth == 10) { swingHit = true; Invoke("SendDamage2", 0.25f); } if (swingHit) { swordAnim.SetTrigger("swing2"); if (target.tag == "RedEnemy") { Invoke("SendDamage1", 0.25f); //target.TakeDamage(damage); } if (target2.tag == "Stain Enemy") { Invoke("SendDamage2", 0.25f); } swingHit = false; } } if (swingHit == false) { swordAnim.SetTrigger("swing"); } }
void SendDamage2() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, 150)) { StainEnemyScript target2 = hit.transform.GetComponent <StainEnemyScript>(); target2.TakeDamage(damage); swingHit = false; } }
//shoot function, creates a raycast in front of player, if it hits the "Blue Enemy", that enemy's script is called and it takes damage public void Shoot() { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit)) { Debug.Log(hit.transform.name); GermEnemyScript target1 = hit.transform.GetComponent <GermEnemyScript>(); StainEnemyScript target2 = hit.transform.GetComponent <StainEnemyScript>(); //TEMP: Get targets gameobject to test if wrong weapon used GameObject targetGO = hit.transform.gameObject; if (target1 != null && target1.tag == "BlueEnemy") { staticForce += 1; target1.TakeDamage(damage); //TEMP: Notify on wrong weapon used } if (target2 != null && target2.tag == "Stain Enemy" && target2.stainHealth > 10) { staticForce += 1; target2.TakeDamage(damage); } else if (targetGO != null && targetGO.tag == "RedEnemy") { StartCoroutine("WrongWeaponNotify"); } //instantiates a particle system to simulate shot hitting the target, currently not working, no idea why GameObject impactGO = Instantiate(_impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); impactGO.GetComponent <ParticleSystem>().Play(); } }