Hi!! Im new to Unity and im working on inventory to my game. I have a GameObject for each slot and when you pickup an item it makes it an child Object where the parent is slot. I need to make the objects stack so when you pickup an item, script also takes sprite name of the object and stores it in a string. The thing is when i try to compare strings both of them give me Null. Look at it by yourself xD
int i = 0;
public SpriteRenderer sprite;
private GameObject objecth;
private Image sprite2;
string sprite3;
string sprite4;
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Player")){
if (inventory.isFull *== false) {*
objecth = Instantiate(itemButton, inventory.slots*.transform, false);*
sprite2 = objecth.GetComponent();
inventory.isFull = true;
sprite3 = sprite2.sprite.name;
sprite4 = sprite.sprite.name.ToString();
Debug.Log(sprite3); //this gives me name of the sprite (thats correct)
Debug.Log(sprite4); //this gives me name of the sprite (thats correct too)
Destroy(gameObject);
}
else
{
Debug.Log(sprite4); //this gives me “Null”
Debug.Log(sprite3); //this gives me “Null” too
if(sprite4 == sprite3)
{
Instantiate(itemButton, inventory.slots*.transform, false);*
Destroy(gameObject);
}
else
{
i++;
}
}
}