72 lines
1.9 KiB
C#
72 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.Events;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Props
|
|
{
|
|
public class Prop_Dynamic_FastRope : MonoBehaviour,IAction,IDescription
|
|
{
|
|
[SerializeField] private LineRenderer lineRenderer;
|
|
[SerializeField] private BoxCollider boxCollider;
|
|
[SerializeField] private Transform startPoint;
|
|
[SerializeField] private Transform rope;
|
|
[SerializeField] private float minDistance;
|
|
[SerializeField] private float maxDistance;
|
|
[SerializeField] private bool isActivated;
|
|
|
|
private Transform Transform;
|
|
|
|
private void Start()
|
|
{
|
|
Transform = transform;
|
|
|
|
Execute(isActivated);
|
|
}
|
|
|
|
public void Execute()
|
|
{
|
|
Execute(isActivated=!isActivated);
|
|
}
|
|
private void Execute(bool activated)
|
|
{
|
|
if (activated is false)
|
|
{
|
|
rope.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
if (Physics.Raycast(Transform.position, Vector3.down, out var hit,maxDistance,1 << 0) is false)
|
|
{
|
|
BIT4Log.Log<Prop_Dynamic_FastRope>("没有找到地面");
|
|
isActivated = false;
|
|
return;
|
|
}
|
|
if(Vector3.Distance(hit.point,Transform.position) < minDistance)
|
|
{
|
|
BIT4Log.Log<Prop_Dynamic_FastRope>($"距离太近,击中了{hit.collider.name}");
|
|
isActivated = false;
|
|
return;
|
|
}
|
|
|
|
rope.gameObject.SetActive(true);
|
|
|
|
|
|
var currentPos = startPoint.position;
|
|
currentPos.y = hit.point.y;
|
|
startPoint.position = currentPos;
|
|
|
|
var position = Transform.position;
|
|
lineRenderer.SetPosition(1, new Vector3
|
|
{
|
|
y = -Vector3.Distance(hit.point, position)
|
|
});
|
|
boxCollider.size = new Vector3(boxCollider.size.x,Vector3.Distance(hit.point,position),boxCollider.size.z);
|
|
boxCollider.center = new Vector3(boxCollider.center.x, -Vector3.Distance(hit.point, position) / 2, boxCollider.center.z);
|
|
}
|
|
|
|
public string Name=>isActivated?"回收绳索":"放出绳索";
|
|
}
|
|
}
|