Unity DrawWireDisc

问题描述 投票:0回答:1

我是 Unity/游戏开发的新手,我想做一些像视频开头那个人展示的事情:https://youtu.be/rSKMYc1CQHE?si=uy-sCvQHlVQFVZTs
所以我尝试用函数 DrawCircle(...) 绘制这些圆圈。我不太确定是否必须在这里使用 .DrawWireDisc 是否正确。你能帮我画一下视频中所示的粒子/圆和盒子吗?到目前为止,我在游戏选项卡和场景选项卡中都看不到这些行。

我必须使用哪些游戏对象?我应该把脚本放在哪里?

感谢您的回复和想法

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEngine;

public class physics : MonoBehaviour
{
    public float gravity = 9.81f;
    public float bounce = 0.8f;

    public Vector2 particlePosition;
    public Vector2 particleVelocity;
    public float particleSize = 1.0f;

    // Update is called once per frame
    void Update()
    {
        particleVelocity += Vector2.down * gravity * Time.deltaTime;
        particlePosition += particleVelocity * Time.deltaTime;

        handleCollision();

        drawCircle(particlePosition, particleSize, Color.red);
    }

    void handleCollision()
    {
        // when particle moves outside of the box, invert velocity and multiply by bounce
    }

    void drawCircle(Vector2 position, float radius, Color colour)
    {
        // what should come here? I know Vector 3 is giving me errors but what else can I use?
        Handles.color = colour;
        Handles.DrawWireDisc(position, Vector3.forward, radius);
    }
}

我已经尝试使用游戏对象来创建带有碰撞器的盒子。我的意思是它有效,但不是我想要的。

c# windows unity-game-engine unityscript
1个回答
0
投票

手柄仅适用于 SceneView,它们是一种调试/设计工具。 在您的情况下,即使在 SceneView 中您也看不到它们,因为它们应该在 OnSceneGUI 方法中调用。

在 Unity 中进行像这样的表示有很多选择。您可以使用 UI、Sprites、Shaders 等。资产商店中有一种非常流行的付费资产,名为“Shapes”,您可以使用。您还可以搜索免费的替代品。经过一番快速谷歌搜索后,我找到了这个另一个 额外提示:每当您的代码未按预期工作时,请参阅 Unity 的文档。

© www.soinside.com 2019 - 2024. All rights reserved.