コード例 #1
0
ファイル: RelayMove.cs プロジェクト: Cubafehis0/Electricity
    void VerticalMove()
    {
        //与玩家1的碰撞检测
        RaycastHit2D hit = CheckCollision.CheckDownCollison(relay.rig, player1Layer, Mathf.Abs(relay.speed.y) * Time.deltaTime);

        if (hit.collider != null)
        {
            return;
        }
        //与玩家2的碰撞检测

        hit = CheckCollision.CheckDownCollison(relay.rig, player2Layer, Mathf.Abs(relay.speed.y) * Time.deltaTime);
        if (hit.collider != null)
        {
            return;
        }
        //着地碰撞检测
        hit = CheckCollision.CheckDownCollison(relay.rig, mapLayer, Mathf.Abs(relay.speed.y) * Time.deltaTime);
        if (hit.collider != null)
        {
            relay.rig.MovePosition(new Vector2(relay.rig.transform.position.x, hit.point.y + relayExtents.y));
            relay.speed.y = 0;
        }
        else//没有着地继续移动
        {
            relay.rig.MovePosition(relay.speed * Time.deltaTime + (Vector2)relay.transform.position);
        }
    }
コード例 #2
0
    void GroundCollision(Player player, int layerMask, string tag)
    {
        //落地检测
        RaycastHit2D hit = CheckCollision.CheckDownCollison(player.rig, layerMask, Mathf.Abs(player.speed.y * Time.deltaTime) + 0.01f);

        if (hit.collider != null)
        {
            if (hit.collider.tag == tag)
            {
                if (player.speed.y < -20)
                {
                    GameObject dropEffect = GameObject.Instantiate(player.dropDustEffect, player.transform.position + new Vector3(0.15f, -0.70f, 0), Quaternion.identity);
                    GameObject.Destroy(dropEffect, 0.3f);
                }
                player.speed.y      = (hit.point.y - player.rig.GetComponent <Collider2D>().bounds.center.y + player.Collider2DExtents.y) / Time.deltaTime;
                player.IsFloat      = false;
                isFinishInitialDrop = true;
                if (hit.collider.tag == player.tag)
                {
                    player.isOnOther = true;
                }
            }
        }
        else
        {
            player.isOnOther = false;
            player.IsFloat   = true;
        }
    }
コード例 #3
0
    void CheckConveyBelt(Player player)
    {
        //传送带加减速
        RaycastHit2D hit = CheckCollision.CheckDownCollison(player.rig, mapLayer, Mathf.Abs(player.speed.y) * Time.deltaTime + 0.01f);

        if (hit.collider != null)
        {
            if (hit.collider.tag == "conveyBelt")
            {
                player.speed.x += 1.5f;
            }
        }
    }
コード例 #4
0
    void CheckMapLayer()
    {
        //地刺和升降台的碰撞检测
        RaycastHit2D hit = CheckCollision.CheckDownCollison(player1.rig, mapLayer, 0.01f);

        if (hit.collider != null)
        {
            if (hit.collider.tag == "prickle")
            {
                GameStatus.IsAlive = false;
            }
        }

        hit = CheckCollision.CheckDownCollison(player2.rig, mapLayer, 0.01f);
        if (hit.collider != null)
        {
            if (hit.collider.tag == "prickle")
            {
                GameStatus.IsAlive = false;
            }
        }

        if (liftPlats.Length > 0)
        {
            player1.IsOnPlat = false;
            for (int i = 0; i < liftPlats.Length && !player1.IsOnPlat; i++)
            {
                liftPlats[i].OnLiftPlat(player1);
            }

            player2.IsOnPlat = false;
            for (int i = 0; i < liftPlats.Length && !player2.IsOnPlat; i++)
            {
                liftPlats[i].OnLiftPlat(player2);
            }
            if (player1.isOnOther && player2.IsOnPlat)
            {
                player1.speed.y = player2.speed.y;
            }
            if (player2.isOnOther && player1.IsOnPlat)
            {
                player2.speed.y = player1.speed.y;
            }
        }
    }