📜  如何在统一 2d 屏幕周围随机生成硬币 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:15.134000             🧑  作者: Mango

代码示例1
void Start()
        {
            for (int i = 0; i < 10; i++)
            {
                float spawnY = Random.Range
                    (Camera.main.ScreenToWorldPoint(new Vector2(0, 0)).y, Camera.main.ScreenToWorldPoint(new Vector2(0, Screen.height)).y);
                float spawnX = Random.Range
                    (Camera.main.ScreenToWorldPoint(new Vector2(0, 0)).x, Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, 0)).x);
     
                Vector2 spawnPosition = new Vector2(spawnX, spawnY);
                Instantiate(banana, spawnPosition, Quaternion.identity);
            }
        }