如何在Unity3D中画一个圆? [英] How can I draw a circle in Unity3D?

查看:1690
本文介绍了如何在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.

推荐答案

我发现此代码有一个大错误.点数(大小)不应为((2 * pi/theta_scale)+ 1"),因为这会导致圆绘制6.28次.大小应为"1/theta_scale + 1".因此,对于theta_scale为0.01的它需要绘制100个点,对于theta_scale为0.1的它需要绘制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.01f;
    public float radius = 3f;
    private int Size;
    private LineRenderer LineDrawer;
    private float Theta = 0f;

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

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

如果您修改大小"中用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天全站免登陆