【Mini Game】2D Game Stick Hero (Endless Mode)

Welcome to the Unity industry QQ exchange group: 956187480
Active project address at the end of the article


Difficulty factor: ★☆☆☆☆
Gameplay: Stick hero, long press the mouse to generate a stick to build bridges and walk through the ravines.
Contents of this article: Briefly record the main code logic and add comments to the code

1: The player controls the main logic

1. Automatic generation of ground

    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 = (

Guess you like

Origin blog.csdn.net/qq_37310110/article/details/122699723