[unity]在unity中创建圆锥体

本文介绍了如何在Unity3D中快速创建圆锥体,提供了两种方法,一种是通过外部建模软件导入,另一种是使用Unity内置的CreateCone脚本。用户只需将CreateCone.cs文件放入项目的Editor目录,即可在 GameObject/Create Other 菜单中找到创建圆锥体的选项。该脚本允许设置圆锥体的顶点数、顶部和底部半径、长度以及开口角度等参数。
摘要由CSDN通过智能技术生成

在国内百度不带还是去google了果然(哈哈我是大自然的搬运工)


解决方法有两个: 

1)利用maya Blender等建模导入,太麻烦,看有没有其他方法,继续找。

2)国外网友贴了一个网址是unity的wifi,网址是 点击打开链接  或者 http://wiki.unity3d.com/index.php?title=CreateCone

CreateCone

Usage

Place this script as  in YourProject/Assets/Editor and a menu item will automatically appear in the "GameObject/Create Other" menu after it is compiled.

使用方法,创建名为"CreateCone.cs"的文档然后放到你的项目/Assets/Editor 中,然后观察Hierarchy面板的create下拉菜单你会发现多了一个Create Other,点进去有cone,这就是圆锥了。以下是创建时可以设置的参数。不懂的找字典查下。

Num Vertices is the number of vertices each end will have.
Radius Top is the radius at the top. The center point will be located at (0/0/0).
Radius Bottom is the radius at the bottom. The center point will be located at (0/0/Length).(底圆的半径大小)
Length is the number of world units long the plane will be (+Z direction).
Opening Angle If this is >0, the top radius is set to 0, and the bottom radius is computed depending on the length, so that the given opening angle is created.(貌似是底圆是多少边形,即越大越接近圆形)
Outside defines whether the outside is visible (default).
Inside defines whether the inside is visible. Set both outside and inside to create a double-sided primitive.
Add Collider creates a matching mesh collider for the cone if checked.

以下是源码,直接粘贴,不放心的点上面链接,进去粘贴就好。是C#的。


using UnityEngine;
using UnityEditor;
using System.Collections;
 
// an Editor method to create a cone primitive (so far no end caps)
// the top center is placed at (0/0/0)
// the bottom center is placed at (0/0/length)
// if either one of the radii is 0, the result will be a cone, otherwise a truncated cone
// note you will get inevitable breaks in the smooth shading at cone tips
// note the resulting mesh will be created as an asset in Assets/Editor
// Author: Wolfram Kresse
public class CreateCone : ScriptableWizard {
   
 
	public int numVertices = 10;
	public float radiusTop = 0f;
	public float radiusBottom = 1f;
	public float length = 1f;
	public float openingAngle = 0f; // if >0, create a cone with this angle by setting radiusTop to 0, and adjust radiusBottom according to length;
	public bool outside = true;
	public bool inside = false;
	public bool addCollider = false;
 
    [MenuItem ("GameObject/Create Other/Cone")]
    static void CreateWizard()
    {
   
        ScriptableWizard.DisplayWizard("Create Cone", typeof(CreateCone));
    }
 
	void OnWizardCreate(){
   
		GameObject newCone=new GameObject("Cone");
		if(openingAngle>0&&openingAngle<180){
   
			radiusTop=0;
			radiusBottom=length*Mathf.Tan(openingAngle*Mathf.Deg2Rad/2);
		}
		string meshName = newCone.name + numVertices + "v" + radiusTop 
  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值