簡體   English   中英

腳本對象在構建時不起作用

[英]Scriptable object doesn't work on build

我希望這可能是我想念的簡單事情。

我有一個ScriptableObject腳本,如下所示:

using UnityEngine;
using System.Collections;

[CreateAssetMenu]
public class Item: ScriptableObject
{
    public string iname;
    public int iindex;
    public Sprite sprite;
    public GameObject itemObject;
    public int value;
    public string description;
    public itemType itemtype;

    public enum itemType
    {

        Consumable,
        Equippable,
    }

}

這在編輯器中工作得很好,但是如果我向Android或Windows發布任何引用ScriptableObject的腳本,它就不起作用。 我錯過了什么?

例如,以下代碼塊似乎根本不執行:

for (int i = 0; i < 3; i++)
{
    int lootnum = Random.Range(0, 4);


    slot1 = itemdb[lootnum];
    tlist[i] = itemdb[lootnum];
    slotlist[i].transform.GetChild(0).GetComponent<Image>().sprite = itemdb[lootnum].sprite;
    slotlist[i].transform.GetChild(0).GetComponent<Image>().enabled = true;
}

代碼中的那些列表是上面腳本中定義的Item類型。 我不知道如何調試這個,因為我在編輯器中沒有出現錯誤或警告。

這是填充庫存的腳本。 那里有一些垃圾但是definitley在編輯器中正常工作。 只是沒有建立。

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

public class Inventory : MonoBehaviour {


    public int invSize;
    public Item slot1;
    public Item tslot1;
    public Item tslot2;
     public Item tslot3;
    public GameObject t1;
    public GameObject t2;
    public GameObject t3;
    public Sprite itemsprite;
    public List<Item> itemdb = new List<Item>();
    public List<Item> items = new List<Item>();
    public List<Item> tlist = new List<Item>();
    public Text stext;
    public Text description;
    public Item selectItem;
    public GameObject selectSlot;
    public Object test2;

    public List<GameObject> slotlist = new List<GameObject>();


    // Use this for initialization
    void Start () {


    }

    // Update is called once per frame
    void Update () {

    }

    public void addItem(Item itemToAdd)
    {
        //items.Add(itemdb[0]);
        for (int i = 0; i < 5; i++)
        {

            if (items[i] == null)
            {
                items[i] = itemToAdd;
                itemsprite = itemToAdd.sprite;

                return;
            }
        }
    }


    public void GenTreasure()
    {





        for (int i = 0; i < 3; i++)
        {
            int lootnum = Random.Range(0, 4);


            slot1 = itemdb[lootnum];
            tlist[i] = itemdb[lootnum];
            slotlist[i].transform.GetChild(0).GetComponent<Image>().sprite = itemdb[lootnum].sprite;
            slotlist[i].transform.GetChild(0).GetComponent<Image>().enabled = true;
        }

    }


    public void Uptext(int indexx)
    {
        stext.text = tlist[indexx].iname;
        selectItem = tlist[indexx];
        selectSlot = slotlist[indexx];
        description.text = selectItem.description;
    }

    public void Take(int index)
    {
        //items.Add(selectItem);
        for (int i = 0; i < invSize; i++)
        {

            if (items[i] == null)
            {
                items[i] = selectItem;
                //   itemsprite = itemToAdd.sprite;
                selectItem = null;
                //   tlist[i] = null;
                //    slotlist[i].transform.GetChild(0).GetComponent<Image>().sprite = null;
                selectSlot.transform.GetChild(0).GetComponent<Image>().enabled = false;

                return;
            }

        }

    }
}

如果腳本不在場景中,它是如何加載的? 它是否使用資產包? 如果是這種情況,則可能會從構建中刪除該類。 您可以在link.xml中包含該類,以確保它包含在內。 另一種選擇是在任何地方簡單地引用包含場景中的腳本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM