This is the script that I am trying to update the shape gameobject and the currentSelectedObject in runtime.
public GameObject currentSelectedObject;
public GameObject shape;
public void RotateClockwise()
{
shape.transform.Rotate(0f, 0f, -10f);
}
public void RotateAntiClockwise()
{
shape.transform.Rotate(0f, 0f, 10f);
}
public void UpdateSelected(GameObject newSelection)
{
if (currentSelectedObject == null)
{
if (shape.GetComponent<DragAndDrop>().IsDragging == true)
{
currentSelectedObject = newSelection;
newSelection = shape;
}
}
and here is the dragging script mentioned that I use to drag the puzzle pieces
private RectTransform rectTransform;
public Image image;
public bool IsDragging;
public void OnBeginDrag(PointerEventData eventData)
{
// throw new System.NotImplementedException();
image.color = new Color32(255, 255, 255, 170);
}
public void OnDrag(PointerEventData eventData)
{
//rectTransform.anchoredPosition += eventData.delta;
transform.position = Input.mousePosition;
IsDragging = true;
}
public void OnEndDrag(PointerEventData eventData)
{
image.color = new Color32(255, 255, 255, 255);
IsDragging = false;
}
// Start is called before the first frame update
void Start()
{
rectTransform = GetComponent<RectTransform>();
image = GetComponent<Image>();
}
Many thanks to anyone that reads this.