/// <summary> /// 碰撞器进入 /// </summary> /// <param name="_other"></param> private void OnTriggerEnter2D(Collider2D _other) { if (_other.gameObject.tag.Equals("Player")) { ExpressionScore.SInstance.AddScore(mAddScore); //加分 SoundEffectController.PlaySound(EatGoldClip, transform.position); //播放吃金币声音 Instantiate(DestroyAnim, transform.position, Quaternion.identity); //生成加分效果 Destroy(gameObject); //销毁自己 } }
public GameObject DestroyAnim; //销毁动画 /// <summary> /// 碰撞器进入 /// </summary> /// <param name="_other"></param> private void OnTriggerEnter2D(Collider2D _other) { if (_other.gameObject.tag.Equals("Player")) { ExpressionScore.SInstance.AddScore(AddScore); //加分 SoundEffectController.PlaySound(AddScoreAudio, transform.position); //播放吃金币声音 if (DestroyAnim != null) //如果销毁动画不是空 { Instantiate(DestroyAnim, transform.position, Quaternion.identity); //生成加分效果 } Destroy(gameObject); //销毁自己 } }
/// <summary> /// 跳的方法 /// </summary> public void Jump() { if (GetCurrentState() == RUN) //如果当前状态为跑 { SetCurrentState(JUMP); SoundEffectController.PlaySound(JumpAudio); //播放音效 mRigidBody2D.velocity = new Vector2(0, 9f); //来个向上的速度 } else if ((GetCurrentState() == JUMP || GetCurrentState() == DROP) && mTwoJumpNum > 0) //如果不是二级跳 { mTwoJumpNum--; //可以二级跳的数目减减 SetCurrentState(TWO_JUMP); //设置当前状态为二级跳 SoundEffectController.PlaySound(SecondJumpAudio); //播放二级跳音效 mRigidBody2D.velocity = new Vector2(0, Mathf.Max(6f, mRigidBody2D.velocity.y + 4)); //来个向上的速度 } }