void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "enemy") { //if collided object has this specified tag LightChanger.Change(); //Decrease the players range if light by specified value; SoundManager.PlaySound("zap"); //Create sound upon collision } if (col.gameObject.tag == "bullet") { LightChanger.Change(); SoundManager.PlaySound("zap"); } if (col.gameObject.tag == "square") { LightChanger.Change(); SoundManager.PlaySound("zap"); } if (col.gameObject.tag == "r1") { LightChanger.Change(); SoundManager.PlaySound("zap"); } if (col.gameObject.tag == "bounds") { LightChanger.Change(); SoundManager.PlaySound("zap"); } }
public void explode() { Collider2D[] objects = Physics2D.OverlapCircleAll(transform.position, fieldOfImpact, LayerToHit); //Check all objects inside fieldOfImpact foreach (Collider2D obj in objects) //for all object inside fieldOfImpact { Vector2 direction = obj.transform.position - transform.position; //direction of enemies being pushed away upon explosion if (obj.gameObject.tag == "enemy") //check if object has this tag { obj.GetComponent <Rigidbody2D>().AddForce(direction * force1); //add force to the enemy to push it away Destroy(obj.gameObject, 0.1f); //destroy enemy after 0.1s of explosion } if (obj.gameObject.tag == "bullet") { obj.GetComponent <Rigidbody2D>().AddForce(direction * force2); } if (obj.gameObject.tag == "wallss") { Destroy(obj.gameObject); } if (obj.gameObject.tag == "r1") { obj.GetComponent <Rigidbody2D>().AddForce(direction * force2); Destroy(obj.gameObject, 0.3f); } } SoundManager.PlaySound("explode"); //instantiate sound upon explosion GameObject ExplosionEffectIns = Instantiate(ExplosionEffect, transform.position, Quaternion.identity); //instantiate explosion effect Destroy(ExplosionEffectIns, 3); //destroy explosion effect after 3s LightChanger.ChangeLess(); //if player explodes, decrease his light by specific value...ChangeLess is a function called from another script(LightChanger) }
// Implement IUnityAdsListener interface methods: public void OnUnityAdsDidFinish(string surfacingId, ShowResult showResult) { // Define conditional logic for each ad completion status: if (showResult == ShowResult.Finished) { // Reward the user for watching the ad to completion. LightChanger.ReChargeMenu(); } else if (showResult == ShowResult.Skipped) { // Do not reward the user for skipping the ad. } else if (showResult == ShowResult.Failed) { Debug.LogWarning("The ad did not finish due to an error."); } }
void Update() { if (Vector2.Distance(transform.position, target.position) < 10) //check if the player is this close (10) from the enemy { if (Vector2.Distance(transform.position, target.position) > stoppingDistance) //decide when the enemy stops chasing the player to prevent colliding { transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime); // Start chasing target GameObject ElectricEffectIns = Instantiate(ElectricEffect, transform.position, Quaternion.identity); //Create the moving effect of the enemy } } if (Vector2.Distance(transform.position, target.position) < 4) //check if the player is this close (4) from the enemy { LightChanger.Black(); //change the light of the player to black } }