【小游戏】2D游戏棍子英雄StickHero(无尽模式)

欢迎加入Unity业内qq交流群:956187480
文末有源工程地址


难度系数: ★☆☆☆☆
游戏玩法: 棍子英雄,鼠标长按生成棍子搭桥,走过沟壑。
本文内容: 简单记录一下主要代码逻辑,给代码添加注释

一:玩家控制主逻辑

1.地面的自动生成

    void Update()
    {
        //无限生成平台
        float halfWidth = lastPlatform.localScale.x * 0.5f;
        while (lastPlatform.position.x - halfWidth < mainCamera.ViewportToWorldPoint(new Vector3(1, 0, 0)).x)
        {
            var prefab = Resources.Load("Prefabs/Ground") as GameObject;
            prefab.transform.localScale = new Vector3(Random.Range(1, 5), 10, 1);//随机生成宽度不一的平台  其中Random.Range(1,5)  随机获取1~5之间的数
            float posX = lastPlatform.position.x + halfWidth + Random.Range(3, maxDistance - prefab.transform.localScale.x);
            lastPlatform = (

猜你喜欢

转载自blog.csdn.net/qq_37310110/article/details/122699723