Ejemplo n.º 1
0
 public void OnCollisionEnter2D(Collision2D collision)
 {
     if (Vector2.Dot(Vector2.up, collision.contacts[0].normal) >= -0.1f)
     {
         if (colliders.Count == 0)
         {
             // if enough down speed and horizontal collision
             if (falling && Vector2.Dot(Vector2.up, collision.contacts[0].normal) > 0.2f)
             {
                 animator.SetTrigger("land");
                 landAudio.Play(Random.Range(1.1f, 1.2f));
             }
             else
             {
                 animator.SetTrigger("quickland");
             }
             animator.ResetTrigger("fly");
             animator.ResetTrigger("jump");
         }
         colliders.Add(collision.gameObject, collision.contacts[0].normal);
         falling = false;
     }
     else
     {
         Debug.Log("Collision upward ignored");
     }
 }
Ejemplo n.º 2
0
        // 播放录音
        private void button3_Play_Click(object sender, EventArgs e)
        {
            try
            {
                if (recorder.Starting)
                {
                    throw new Exception("请先结束录音");
                }

                // 如果当前未播放,则播放
                if (!playAudio.IsPlaying())
                {
                    if (!File.Exists(FileName))
                    {
                        throw new Exception("文件不存在");
                    }
                    playAudio.Play(FileName);
                }
                else
                {
                    playAudio.ClosePlay();
                }
            }
            catch (Exception ex)
            {
                label3.Text = ex.Message;
            }
        }
Ejemplo n.º 3
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        if ((Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) && !PlayerManager.isLock())
        {
            if (Action())
            {
                PlayAudio.Play(SingletonTMono <PlayerManager> .Instance.gameObject, "Sound/交互成功提示音");
            }

            //switch ()
        }
    }
Ejemplo n.º 4
0
    protected void AnimationEvent_Hit()
    {
        bool hitEnemy  = false;
        bool hitGround = false;

        GameObject[] coll = colliders.ToArray();
        foreach (GameObject collider in coll)
        {
            if (collider == null)
            {
                Debug.Log("Null collider");
                colliders.Remove(collider);
                continue;
            }
            if (enemyLayerMask.Contains(collider.layer))
            {
                hitEnemy = true;
                Vector2 dir = (collider.Position() - player.Position()).normalized;

                if (Vector2.Dot(dir, Vector2.down) > 0.707f)
                {
                    player.Q <Rigidbody2D>().SetVelocity(-dir * selfKnockBackForce);
                }

                float angle = Mathf.Atan2(dir.y, dir.x);

                Instantiate(prefabHitPixelLine, collider.transform.position, Quaternion.AngleAxis(angle * 180 / Mathf.PI, Vector3.forward), collider.transform);
                Instantiate(prefabHitPixelLine2, player.transform.position, Quaternion.AngleAxis(angle * 180 / Mathf.PI, Vector3.forward), player.transform);

                collider.Q <Rigidbody2D>().AddForce(dir * knockBackForce, ForceMode2D.Impulse);
                if (collider.Q <Health>().Hit(1))
                {
                    finalBlowAudio.Play(Random.Range(0.95f, 1.05f));
                    Instantiate(prefabHitPixel, collider.transform.position, Quaternion.AngleAxis(angle * 180 / Mathf.PI, Vector3.forward));
                }
                else
                {
                    hitAudio.Play(Random.Range(1f, 1.2f));
                }
            }
            else if (groundLayerMask.Contains(collider.layer))
            {
                hitGround = true;
            }
        }

        if (hitEnemy && hitGround)
        {
            hitGroundAudio.Play(Random.Range(1.15f, 1.20f));
        }
    }
Ejemplo n.º 5
0
    private void Hurt(Collider2D collision)
    {
        m_CanBeHurt = false;
        //Debug.Log("!!!!!!!!!!!OnTrigher 12");
        m_bloodNum--;

        Invoke("EndProtectTime", this.m_hurtProtectTime);
        Vector3 off = (this.transform.position - collision.transform.position).normalized * springBackFactor;

        m_rigidbody.velocity = Vector2.zero;
        m_rigidbody.AddForce(new Vector2(off.x, off.y), ForceMode2D.Impulse);
        PlayAudio.Play(this.gameObject, "Sound/受伤");
        ShowBlood();
    }
Ejemplo n.º 6
0
    private void Dash_started(UnityEngine.InputSystem.InputAction.CallbackContext obj)
    {
        if (Time.time > lastDash + delayBetweenDash)
        {
            dashDir = controls.FreeMovement.Move.ReadValue <Vector2>();
            if (dashDir.x == 0)
            {
                dashDir = new Vector2(axisFacing, 0);
            }
            else
            {
                dashDir = new Vector2(dashDir.x, 0);
            }

            dashAudio.Play();
            animator.SetTrigger("dash");
            lastDash = Time.time;
        }
    }
Ejemplo n.º 7
0
    private IEnumerator ManageState()
    {
        audio.Play(hit);
        yield return(new WaitForSeconds(0.5f));

        bar.GetComponent <Animator>().SetTrigger("UnEquip");
        if (ratAni.GetComponent <RatStats>().health <= 0)
        {
            yield return(new WaitForSeconds(0.5f));

            StartCoroutine(ratAni.GetComponent <RatStats>().Flee());
            states.ChangeBehaviour(StateManager.RatState.IDLE);
            yield break;
        }
        camAni.SetTrigger("Rage");
        ratAni.SetTrigger("Rage");
        yield return(new WaitForSeconds(1.8f));

        states.ChangeBehaviour(StateManager.RatState.ATTACK);
    }
Ejemplo n.º 8
0
    private void Jump_started(UnityEngine.InputSystem.InputAction.CallbackContext obj)
    {
        // 100ms bonus to jump off platform !
        if (colliders.Count > 0 || Time.time < lastTimeGrounded + bonusTimeJump)
        {
            lastJump = Time.time;
            animator.SetTrigger("jump");
            jumpAudio.Play(Random.Range(1.2f, 1.3f));

            // si au moins une collision est proche de l'horizontal
            if (colliders.Any(x => Vector2.Dot(Vector2.up, x.Value) > 0.2f))
            {
                rgby.velocity = Vector2.up * jumpVelocity;
            }
            else
            {
                Vector2 dir = (Vector2.up + colliders.FirstOrDefault().Value).normalized;
                rgby.velocity = dir * jumpVelocity;
            }
        }
    }
Ejemplo n.º 9
0
 public void Hit()
 {
     painAudio.Play();
 }
Ejemplo n.º 10
0
    //玩家移动
    private void MoveUpdate()
    {
        if (m_lock)
        {
            return;
        }
        const int Wall  = 1 << 8;
        bool      left  = Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A);
        bool      right = Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D);
        bool      up    = Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W);
        bool      down  = Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S);

        if (Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.A) || m_downCollider.IsTouchingLayers(Wall))
        {
            m_canmove = true;
        }
        if (Mathf.Abs(m_rigidbody.velocity.x) > 0.01f)
        {
            if (m_rigidbody.velocity.x > 0)
            {
                m_actorState.SetState(ActorState.State.Right);
            }
            else
            {
                m_actorState.SetState(ActorState.State.Left);
            }
        }
        else
        {
            m_actorState.SetState(ActorState.State.Idle);
        }

        if (left && m_canmove)
        {
            m_actorState.SetState(ActorState.State.Left);
            //向左移动
            m_rigidbody.AddForce(new Vector2(-ConstData.PlayerAcc, 0), ForceMode2D.Force);
            //最大速度
            if (m_rigidbody.velocity.x < -ConstData.PlayerMaxVel)
            {
                m_rigidbody.velocity = new Vector2(-ConstData.PlayerMaxVel, m_rigidbody.velocity.y);
            }
            //爬墙
            if (m_leftCollider.IsTouchingLayers(Wall) && !m_downCollider.IsTouchingLayers(Wall))
            {
                m_actorState.SetState(ActorState.State.LeftWall);
                m_rigidbody.AddForce(new Vector2(0, ConstData.PlayerFri), ForceMode2D.Force);
            }
        }

        if (right && m_canmove)
        {
            //向右移动
            m_rigidbody.AddForce(new Vector2(ConstData.PlayerAcc, 0), ForceMode2D.Force);
            //最大速度
            if (m_rigidbody.velocity.x > ConstData.PlayerMaxVel)
            {
                m_rigidbody.velocity = new Vector2(ConstData.PlayerMaxVel, m_rigidbody.velocity.y);
            }
            //爬墙
            if (m_rightCollider.IsTouchingLayers(Wall) && !m_downCollider.IsTouchingLayers(Wall))
            {
                m_actorState.SetState(ActorState.State.RightWall);
                m_rigidbody.AddForce(new Vector2(0, ConstData.PlayerFri), ForceMode2D.Force);
            }
        }

        //跳跃
        if (up)
        {
            //平地
            if (m_downCollider.IsTouchingLayers(Wall))
            {
                m_doubleJump = true;
                m_rigidbody.AddForce(new Vector2(0, ConstData.PlayerJump), ForceMode2D.Impulse);
                PlayAudio.Play(this.gameObject, "Sound/跳跃3");
            }
            else
            //爬墙跳
            if (m_rightCollider.IsTouchingLayers(Wall) && right)
            {
                PlayAudio.Play(this.gameObject, "Sound/跳跃2");
                m_canmove    = false;
                m_doubleJump = false;
                m_rigidbody.AddForce(new Vector2(-ConstData.PlayerRef, ConstData.PlayerJump * 1.3f), ForceMode2D.Impulse);
            }
            else
            if (m_leftCollider.IsTouchingLayers(Wall) && left)
            {
                PlayAudio.Play(this.gameObject, "Sound/跳跃2");
                m_canmove    = false;
                m_doubleJump = false;
                m_rigidbody.AddForce(new Vector2(ConstData.PlayerRef, ConstData.PlayerJump * 1.3f), ForceMode2D.Impulse);
            }
            else
            //双跳
            if (m_doubleJump)
            {
                PlayAudio.Play(this.gameObject, "Sound/跳跃3");
                m_doubleJump         = false;
                m_rigidbody.velocity = new Vector2(m_rigidbody.velocity.x, 0);
                m_rigidbody.AddForce(new Vector2(0, ConstData.PlayerJump), ForceMode2D.Impulse);
            }
        }
    }