如何在 Unity3D 中绘制圆? [英] How can I draw a circle in Unity3D?

查看:84
本文介绍了如何在 Unity3D 中绘制圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Unity 3d 中绘制圆?我想在不同的对象周围画一个圆圈.圆的半径不同,圆有纹理——正方形.

How to draw circle in Unity 3d? I want to draw a circle around different objects. The radiuses of the circles are different and the circles have textures - squares.

推荐答案

我发现这段代码有一个大错误.点数 (Size) 不应为(2 * pi/theta_scale) + 1";因为这会导致圆圈绘制 6.28 次.大小应该是1/theta_scale + 1".因此,对于 0.01 的 theta_scale 需要绘制 100 个点,对于 0.1 的 theta_scale 需要绘制 10 点.否则将分别绘制 62 次和 628 次.这是我使用的代码.

I found a big error with this code. The number of points (Size) shouldn't be "(2 * pi / theta_scale) + 1" because this causes the circle to draw 6.28 times. The size should be "1 / theta_scale + 1". So for a theta_scale of 0.01 it needs to draw 100 points, and for a theta_scale of 0.1 it needs to draw 10 points. Otherwise it would draw 62 times and 628 times respectively. Here is the code I used.

using UnityEngine;
using System.Collections;

public class DrawRadar: MonoBehaviour {
    public float ThetaScale = 0.01 f;
    public float radius = 3 f;
    private int Size;
    private LineRenderer LineDrawer;
    private float Theta = 0 f;

    void Start() {
        LineDrawer = GetComponent < LineRenderer > ();
    }

    void Update() {
        Theta = 0 f;
        Size = (int)((1 f / ThetaScale) + 1 f);
        LineDrawer.SetVertexCount(Size);
        for (int i = 0; i < Size; i++) {
            Theta += (2.0 f * Mathf.PI * ThetaScale);
            float x = radius * Mathf.Cos(Theta);
            float y = radius * Mathf.Sin(Theta);
            LineDrawer.SetPosition(i, new Vector3(x, y, 0));
        }
    }
}

如果修改Size"中的数字即除以ThetaScale,你可以制作一个扫描仪表/饼图类型的图形.

If you modify the number in "Size" that is divided by ThetaScale, you can make a sweeping gauge/pie chart type graphic.

这篇关于如何在 Unity3D 中绘制圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆