63 lines
1.3 KiB
C#
63 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
public class PhysicCable : MonoBehaviour
|
|
{
|
|
[FormerlySerializedAs("StartTranform")] public Transform startTransform;
|
|
|
|
public PhysicLineSegment physicLine;
|
|
|
|
private Transform targetTransform;
|
|
private bool isEnabled;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
physicLine = transform.GetComponent<PhysicLineSegment>();
|
|
}
|
|
|
|
public void Init(Vector3 endPos)
|
|
{
|
|
physicLine.Initialize(startTransform.position, endPos);
|
|
}
|
|
|
|
public void HideCable()
|
|
{
|
|
GetComponent<LineRenderer>().enabled = false;
|
|
}
|
|
|
|
public void ShowCable()
|
|
{
|
|
GetComponent<LineRenderer>().enabled = true;
|
|
}
|
|
|
|
public void SetEnabled(bool enabled)
|
|
{
|
|
isEnabled = enabled;
|
|
GetComponent<LineRenderer>().enabled = enabled;
|
|
}
|
|
|
|
public void SetTarget(Transform target)
|
|
{
|
|
targetTransform = target;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isEnabled)
|
|
{
|
|
// 更新起点位置
|
|
if (startTransform != null)
|
|
{
|
|
physicLine.UpdateStart(startTransform.position);
|
|
}
|
|
|
|
// 更新终点位置
|
|
if (targetTransform != null)
|
|
{
|
|
physicLine.UpdatePlug(targetTransform);
|
|
}
|
|
}
|
|
}
|
|
}
|