using UnityEngine; [ExecuteInEditMode] public class WalkRope : MonoBehaviour { public GameObject bridge; [HideInInspector] public MegaRopeDeform mod; public float offset; public bool checkonbridge; public float weight = 1f; private Mesh mesh; private void LateUpdate() { if (!bridge) { return; } if (mod == null) { mod = bridge.GetComponent(); } if (mesh == null) { MeshFilter component = bridge.GetComponent(); mesh = component.sharedMesh; } if (!mod || !mesh) { return; } int axis = (int)mod.axis; Vector3 position = base.transform.position; Vector3 point = mod.transform.worldToLocalMatrix.MultiplyPoint(position); bool flag = true; if (checkonbridge) { flag = ((point.x > mesh.bounds.min.x && point.x < mesh.bounds.max.x && point.z > mesh.bounds.min.z && point.z < mesh.bounds.max.z) ? true : false); } if (flag) { float num = (point[axis] - mod.soft.masses[0].pos.x) / (mod.soft.masses[mod.soft.masses.Count - 1].pos.x - mod.soft.masses[0].pos.x); if (num > 0f || num < 1f) { point.y = mod.SetWeight(point[axis], weight).y + offset * 0.01f; base.transform.position = bridge.transform.localToWorldMatrix.MultiplyPoint(point); } } else { SetPos(mod, 0f); } } public void SetPos(MegaRopeDeform mod, float alpha) { mod.weightPos = alpha * 100f; mod.weight = weight; } }