I have looked all over the internet and every question says this is fixed but I am experiencing some trouble. This is my code:
private Vector3 startingPos;
[HideInInspector]
public bool empty;
private bool hovered;
private bool waitingForSeconds;
private float timeSinceLastUpdate;
private float scale = 1000f;
[HideInInspector]
public GameObject item;
[HideInInspector]
public Texture itemIcon;
private GameObject player;
private WeaponManager wm;
private Inventory inventory;
private GameObject[] craftable;
public GameObject slotHolder;
private Transform[] slots;
private void Update()
{
float mouseX = Input.GetAxis("Mouse X") * scale * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * scale * Time.deltaTime;
print(mouseX + " " + mouseY);
if (item)
{
empty = false;
itemIcon = item.GetComponent<Item>().icon;
}
else
{
empty = true;
itemIcon = null;
}
this.GetComponent<RawImage>().texture = itemIcon;
if (waitingForSeconds) timeSinceLastUpdate += Time.deltaTime;
else timeSinceLastUpdate = 0f;
if (timeSinceLastUpdate > 1f && item)
transform.position = new Vector2(mouseX, mouseY);
}
public void OnPointerDown(PointerEventData eventData)
{
if (hovered)
waitingForSeconds = true;
}
public void OnPointerUp(PointerEventData eventData)
{
waitingForSeconds = false;
if (hovered)
{
transform.position = startingPos;
UseItem();
}
else
{
foreach (GameObject craftableItemSlot in craftable)
{
if (craftableItemSlot.GetComponent<CraftableItem>().hovered)
{
if (craftableItemSlot.GetComponent<RawImage>().texture == null)
{
craftableItemSlot.GetComponent<RawImage>().texture = itemIcon;
itemIcon = null;
transform.position = startingPos;
craftableItemSlot.GetComponent<CraftableItem>().CheckForRequiredItems();
break;
}
else
{
transform.position = startingPos;
}
}
}
// get the closest slot so we can switch positions
Transform closestSlot = GetClosestSlot(slots);
// switch positions
transform.position = closestSlot.position;
closestSlot.position = startingPos;
}
}
I have no idea what is going on because the mouseX and mouseY are sitting in the corner and it shouldn't be, when I print the values they are these small decimal numbers but I am multiplying by 1000. Am I using the wrong axis or can somebody tell me how to fix it because I am stuck.
Thank you!