-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.cs
More file actions
28 lines (23 loc) · 735 Bytes
/
box.cs
File metadata and controls
28 lines (23 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class box : MonoBehaviour
{
private BoxCollider2D boxCollider;
public Image Image;
private void Start()
{
// Get the reference to the BoxCollider2D component
boxCollider = GetComponent<BoxCollider2D>();
// Get the reference to the Image component representing the inventory slot
Image slotImage = GetComponent<Image>();
// Calculate the size of the Image
Vector2 newSize = slotImage.rectTransform.sizeDelta;
// Set the new size of the BoxCollider2D
if (boxCollider != null)
{
boxCollider.size = newSize;
}
}
}