/* * The OnTriggerEnter function, void return type, parameter: Collider ***Please note that this is different then the others*** * If (tag of the Collider parameter equals the enemy tag) * -Create a variable with the type EnemyDamage and use the GetComponent in the Collider parameter to get a referece * to the EnemyDamage script. * -Create a switch statement in which you'll put the enemy type variable in the EnemyDamage script into the parenthesis * -A case for the first enemy type * -Call the Damage function from the EnemyDamage script and pass the weak damage variable into it * -A case for the second enemy type * -Call the Damage function from the EnemyDamage script and pass the strong damage variable into it * -A case for the third enemy type * -Call the Damage function from the EnemyDamage script and pass the super strong damage variable into it * -Destroy this bullet ***Make sure that this is included in the if statement*** */ void OnTriggerEnter(Collider collider) { if (collider.tag == "Enemy") { EnemyDamage enemydamage = collider.GetComponent <EnemyDamage>(); switch (enemydamage.enemytype) { case EnemyDamage.EnemyType.weak: enemydamage.Damage(weakDamage); break; case EnemyDamage.EnemyType.strong: enemydamage.Damage(strongDamage); break; case EnemyDamage.EnemyType.superstrong: enemydamage.Damage(superStrongDamage); break; default: break; } Destroy(gameObject); } }
public void Fire() { if (!GameManager.instance.isGameover) { RaycastHit hit; if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit)) { if (hit.transform.tag == "Enemy" || hit.transform.name == "balloon1(Clone)" || hit.transform.name == "balloon2(Clone)" || hit.transform.name == "balloon3(Clone)") { EnemyDamage e = hit.collider.GetComponent <EnemyDamage>(); e.Damage(); //Destroy(hit.transform.gameObject, 2f); Instantiate(smoke, hit.point, Quaternion.LookRotation(hit.normal)); } else { Instantiate(gunshoot, hit.point, Quaternion.LookRotation(hit.normal)); } } } }