From 6fc0fee7d23f1ee14189ac28ae785aa8581f032e Mon Sep 17 00:00:00 2001 From: Jordan Date: Sat, 4 Feb 2023 16:26:20 +1100 Subject: [PATCH] vine prefab --- Assets/Prefab/Vine.prefab | 3 ++ Assets/Prefab/Vine.prefab.meta | 7 ++++ Assets/Scenes/BoatTest.unity | 4 +- Assets/vine.cs | 69 ++++++++++++++++++++++++++++++++++ Assets/vine.cs.meta | 11 ++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Assets/Prefab/Vine.prefab create mode 100644 Assets/Prefab/Vine.prefab.meta create mode 100644 Assets/vine.cs create mode 100644 Assets/vine.cs.meta diff --git a/Assets/Prefab/Vine.prefab b/Assets/Prefab/Vine.prefab new file mode 100644 index 0000000..39aa8b6 --- /dev/null +++ b/Assets/Prefab/Vine.prefab @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e123b7105c7223554b0ed640c31956816dc53124adda524add59c94910ddd78 +size 7165 diff --git a/Assets/Prefab/Vine.prefab.meta b/Assets/Prefab/Vine.prefab.meta new file mode 100644 index 0000000..32b1bc7 --- /dev/null +++ b/Assets/Prefab/Vine.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 16732dd06c6df5b4c883cb899f5108e4 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/BoatTest.unity b/Assets/Scenes/BoatTest.unity index 8acac7e..585a17e 100644 --- a/Assets/Scenes/BoatTest.unity +++ b/Assets/Scenes/BoatTest.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fb8245f8af05b8a05903216fc9b8857790dec636f40beb0dec6961953c67a175 -size 47466 +oid sha256:51c8759d1d74c0e958bb8df7ddfd88a5e93a301bf4e288b3bd02954940af9ae5 +size 47470 diff --git a/Assets/vine.cs b/Assets/vine.cs new file mode 100644 index 0000000..94b6847 --- /dev/null +++ b/Assets/vine.cs @@ -0,0 +1,69 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[ExecuteInEditMode] +public class vine : MonoBehaviour +{ + private LineRenderer lineRenderer; + + [SerializeField] + private GameObject position1; + [SerializeField] + private GameObject position2; + + private Vector3 lastPosition1; + private Vector3 lastPosition2; + private float lastDipMagnitude; + private int lastNumberPoints; + + [SerializeField] + private AnimationCurve vineCurve; + [SerializeField] + private float dipMagnitude = 1f; + [SerializeField] + private int numberOfPoints = 20; + + // Start is called before the first frame update + void Awake() + { + lineRenderer = GetComponent(); + } + + void Update() + { + //if both positions are defined + if (position1 != null && position2 != null) + { + //if either of the points have moved + if ((position1.transform.position != lastPosition1) || (position2.transform.position != lastPosition2) || (dipMagnitude != lastDipMagnitude) || (numberOfPoints != lastNumberPoints)) + { + Recalculate(); + } + } + } + + [ContextMenu("Recalculate")] + void Recalculate() + { + lineRenderer.positionCount = numberOfPoints; + + //set start and end + lineRenderer.SetPosition(0, position1.transform.position); + lineRenderer.SetPosition(lineRenderer.positionCount-1, position2.transform.position); + + for (int i = 0; i