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"); } } }
//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(); } }