Quick over view of what i am trying to do~i am trying to set up a game board(like chess)that a player can drag and drop the pieces where they want(like a custom layout of pieces) then save where they placed them then go into a game with their set up
what i have set up is basically 40+ image prefabs layed out to represent the game board then a panel containing all the images(that represent the units) that can be dragged and dropped onto one of the placeholers
the problem i am having is that in my script it is overriding the sprite that is already there and not actually changing it(visualy it changes but physically is does not). does anyone know another way of doing this so that the image i am dropping can maybe become the parent of the placeholder image or actually change the price in the inspector
any help would be appreciated
here is my code for the droping image, i believe the problem can be fixed in the “OnDrop”
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DropMe : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler
{
public Image containerImage;
public Image receivingImage;
private Color normalColor;
public Color highlightColor = Color.yellow;
public void OnEnable ()
{
if (containerImage != null)
normalColor = containerImage.color;
}
public void OnDrop(PointerEventData data)
{
containerImage.color = normalColor;
if (receivingImage == null)
return;
Sprite dropSprite = GetDropSprite (data);
if (dropSprite != null)
receivingImage.overrideSprite = dropSprite;
}
public void OnPointerEnter(PointerEventData data)
{
if (containerImage == null)
return;
Sprite dropSprite = GetDropSprite (data);
if (dropSprite != null)
containerImage.color = highlightColor;
}
public void OnPointerExit(PointerEventData data)
{
if (containerImage == null)
return;
containerImage.color = normalColor;
}
private Sprite GetDropSprite(PointerEventData data)
{
var originalObj = data.pointerDrag;
if (originalObj == null)
return null;
var srcImage = originalObj.GetComponent<Image>();
if (srcImage == null)
return null;
return srcImage.sprite;
}
}
i added a image if my inspector, the receiving image is what should change but it stays the same