MotionCapture/Assets/Bonds.cs
2023-02-24 18:18:56 +08:00

49 lines
1.4 KiB
C#

using UnityEngine;
namespace Models
{
public class Bonds
{
private GameObject start;
private GameObject end;
private GameObject bond;
public Bonds(GameObject start,GameObject end,float scale)
{
this.start = start;
this.end = end;
bond = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
bond.transform.localScale = new Vector3(scale/2, scale/2, scale/2);
}
public void UpdateBond()
{
var startpos = start.transform.position;
var endpos = end.transform.position;
Vector3 rightPosition = (startpos + endpos) / 2;
Vector3 rightRotation = endpos - startpos;
float HalfLength = Vector3.Distance(startpos, endpos) / 2;
float LThickness = 0.1f;//线的粗细
//创建圆柱体
//bond.gameObject.transform.parent = transform;
bond.transform.position = rightPosition;
bond.transform.rotation = Quaternion.FromToRotation(Vector3.up, rightRotation);
bond.transform.localScale = new Vector3(LThickness, HalfLength, LThickness);
//这里可以设置材质,具体自己设置
bond.GetComponent<Renderer>().material.color = Color.cyan;
}
}
}