From 947a8a3edf3086a294d2cd38a42b5bfad80c854d Mon Sep 17 00:00:00 2001 From: rudderbucky Date: Thu, 7 Jan 2021 18:40:26 -0800 Subject: [PATCH] Bugfix offset breaking on new parts --- .../Ship Builder Scripts/ShipBuilderCursorScript.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/HUD Scripts/Ship Builder Scripts/ShipBuilderCursorScript.cs b/Assets/Scripts/HUD Scripts/Ship Builder Scripts/ShipBuilderCursorScript.cs index 2e4d4370a..1a01e3a6d 100644 --- a/Assets/Scripts/HUD Scripts/Ship Builder Scripts/ShipBuilderCursorScript.cs +++ b/Assets/Scripts/HUD Scripts/Ship Builder Scripts/ShipBuilderCursorScript.cs @@ -67,8 +67,15 @@ public void GrabPart(ShipBuilderPart part) { parts.Add(part); part.rectTransform.SetAsLastSibling(); } - // offset = Vector2.zero; - offset = part.GetComponent().anchoredPosition - GetComponent().anchoredPosition; + + // code to ensure part does not snap to cursor immediately + var pos = part.GetComponent().anchoredPosition; + + // if the initial position is zero that means this is a new part, don't set an offset + if(pos == Vector2.zero) + offset = Vector2.zero; + else + offset = pos - GetComponent().anchoredPosition; currentPart = part; } void PlaceCurrentPart() {