コード例 #1
0
    void Eggs(AllData allData)
    {
        float[][]  vels     = allData.egg.vels;
        float[][]  transes  = allData.egg.transes;
        string[][] allItems = allData.egg.allItems;

        for (int i = 0; i < allData.egg.vels.Length; i++)
        {
            CapsuleController e = Instantiate(eggPrefab, Vector3.zero, Quaternion.identity);
            e.transform.position = new Vector3(transes[i][0], transes[i][1], 0);
            e.transform.rotation = Quaternion.Euler(0, 0, transes[i][2]);
            Rigidbody2D rb = e.GetComponent <Rigidbody2D>();
            rb.velocity = new Vector2(vels[i][0], vels[i][1]);
            for (int j = 0; j < allItems[i].Length; j++)
            {
                Item it = Instantiate(StaticFunctions.GetItemFromString(allItems[i][j]), transform.position, Quaternion.identity);
                e.AddItem(it);
            }
        }
    }
コード例 #2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.GetComponent <Item>())
        {
            //so its an item...

            //okay now load egg with item
            if (egg)
            {
                //now update the sprite display
                float color = (egg.items.Count * 1f / maxItems * 1f);
                capacityDisplay.color = new Color((1 - color), color, 0, 1);
                if (egg.items.Count < maxItems)
                {
                    //print(other.name);
                    egg.AddItem(other.GetComponent <Item>());
                }
                else
                {
                    StartCoroutine(LaunchEgg());
                }
            }
            else
            {
                //if no egg, reject
                other.GetComponent <Rigidbody2D>().AddForce(firePoint.up * -200);
                //if not launching, that means no egg is being created to replace. So, another must be made
                if (!launching)
                {
                    egg = Instantiate(eggPrefab, firePoint.position, firePoint.rotation);
                    egg.transform.parent = transform;
                    egg.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
                    egg.AddItem(other.GetComponent <Item>());
                }
            }
        }
    }