private void OnCollisionEnter2D(Collision2D other) //敌人的控制类 { if (other.gameObject.tag == "enemy") //消灭敌人的方法和碰撞敌人产生的效果 { enemy_Controller enemy = other.gameObject.GetComponent <enemy_Controller>(); //申明父类,将enemy_Controller类通过enemy实例化 if (anim.GetBool("falling")) { enemy.JumpOn();//用实例化类完成物体销毁 rb.velocity = new Vector2(rb.velocity.x, jumpforce); anim.SetBool("jumping", true); anim.SetBool("crouching", false); } else if (transform.position.x < other.transform.position.x)//实现与敌人碰撞时受伤的效果 { rb.velocity = new Vector2(-5, rb.velocity.y); //hurtAudio.Play(); SoundMananger.sound_class.HurtAudio();//播放受伤音效 isHurt = true; } else if (transform.position.x > other.transform.position.x) { rb.velocity = new Vector2(5, rb.velocity.y); //hurtAudio.Play(); SoundMananger.sound_class.HurtAudio();//播放受伤音效 isHurt = true; } } }
void OnCollisionEnter2D(Collision2D other) { enemy_Controller cont = other.gameObject.GetComponent <enemy_Controller>(); Enmy_Controllerbasic basic = other.gameObject.GetComponent <Enmy_Controllerbasic>(); if (cont != null) { furry.movement = false; FindObjectOfType <GameManager>().EndGame(); } else if (basic != null) { furry.movement = false; FindObjectOfType <GameManager>().EndGame(); } else if (other.gameObject.tag == "spike") { furry.movement = false; FindObjectOfType <GameManager>().EndGame(); } }