using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public GameObject obj1;
public GameObject obj2;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
drawCylinder(obj1.transform.position,obj2.transform.position);
}
private Dictionary<int, Mesh> _meshMap = new Dictionary<int, Mesh>();
private void drawCylinder(Vector3 a, Vector3 b)
{
float length = (a - b).magnitude;
Graphics.DrawMesh(getCylinderMesh(length),
Matrix4x4.TRS(a, Quaternion.LookRotation(b - a), Vector3.one),obj1.GetComponent<MeshRenderer>().material
,
gameObject.layer);
}//通过obj1.GetComponent<MeshRenderer>().material改圆柱材质
private Mesh getCylinderMesh(float length)
{
int lengthKey = Mathf.RoundToInt(length *
Unity两个物体之间动态生成圆柱
最新推荐文章于 2023-03-09 14:55:16 发布
本文介绍了如何在Unity中实现两个动态移动的物体之间,根据它们的位置实时生成连接它们的圆柱体,以展示物体间的动态连接效果。通过C#脚本控制物体位置变化,并利用Unity的图形API在世界空间中绘制圆柱形线条,实现这一功能。

最低0.47元/天 解锁文章

886





