samedi 14 mars 2020

Getting a compiling error with else-statement [closed]

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

    public class Inventory : MonoBehaviour
    {

        //Variables
        public bool inventoryEnabled;
        public GameObject inventory;
        public GameObject itemDatabase;
        private Transform[] slot;
        public GameObject slotHolder;

        private bool pickedUpItem;


        //Fumctions
        public void Start()
        {
            GetAllSlots();
        }

        public void Update()
        {
            //Enabling and disabling inventory
            if (Input.GetKeyDown(KeyCode.I))
                inventoryEnabled = !inventoryEnabled;

            if (inventoryEnabled)
                inventory.SetActive(true);
            else
                inventory.SetActive(false);

        }



        public void OnTriggerEnter(Collider other)
        {
            if (other.tag == "Item");
            {
                AddItem(other.gameObject);

            }
        }


        public void AddItem(GameObject item)
        {
            if(item.GetComponent<ItemPickup>().craftMaterial == false);
            {
                GameObject rootItem;
                rootItem = item.GetComponent<ItemPickup>().rootItem;

                for (int i = 0; i < 25; i++)
                {
                    if(slot[i].GetComponent<Slot>().empty == true && item.GetComponent<ItemPickup>().pickedUp == false)
                    {
                        slot[i].GetComponent<Slot>().item = rootItem;
                        item.GetComponent<ItemPickup>().pickedUp = true;
                        Destroy(item);
                    }   
            }
        } else {  
                for (int i = 0; i < 25; i++)
                {
                    if(slot[i].GetComponent<Slot>().empty == true && item.GetComponent<ItemPickup>().pickedUp == false)
                    {
                        slot[i].GetComponent<Slot>().item = rootItem;
                        item.GetComponent<ItemPickup>().pickedUp = true;
                        item.transform.parent = itemDatabase.transform;
                        //item.SetActive(false);
                    }
                }
            }
        }

        public void GetAllSlots() 
        {
            slot = new Transform[25];
            for(int i = 0; i < 25; i++)
            {
                slot[i] = slotHolder.transform.GetChild(i);

        } 
    }
}

Hey fellas, I need your help! I'm kinda new at this, been troubleshooting this error for hours, tried everything (exept standing on my head) which I'm about to try cause I'm frostrated! Anyway, Unity shows an "Error CS1513: } expected" in line (65,11) which is the "} else {". Maybe my problem is bigger than that. Please give a glance with experienced eyes.

P.s I know you pros are tired of newbiez. Really, been googling for hours before coming here! It's a simple script aaand it's embarrassing...

Aucun commentaire:

Enregistrer un commentaire