コード例 #1
0
ファイル: PlayerMovement.cs プロジェクト: bzhai155/gunsnake
    private bool CheckUnlockDoor(Direction dir)
    {
        RaycastHit2D rh;
        Vector3      rcDir = Vector3.zero;

        switch (dir)
        {
        case Direction.right:
            rcDir = Vector3.right;
            break;

        case Direction.down:
            rcDir = Vector3.down;
            break;

        case Direction.left:
            rcDir = Vector3.left;
            break;

        case Direction.up:
            rcDir = Vector3.up;
            break;
        }
        rh = Physics2D.Raycast(transform.position, rcDir, 1, wallLayerMask);

        if (rh.collider != null && canOpenChest)
        {
            Door d = rh.collider.gameObject.GetComponent <Door>();
            //Debug.Log("checking door " + d.isLocked + "  " + d.isClosed + " " + PlayerInventory.HasKeys() + " " + PlayerInventory.keys);
            if (d != null && d.isLocked && d.isClosed && PlayerInventory.HasKeys())
            {
                PlayerInventory.AddKey(-1);
                d.UnlockDoor();

                return(true);
            }

            LootActivatorTile l = rh.collider.gameObject.GetComponent <LootActivatorTile>();
            if (l != null)
            {
                canOpenChest = false;

                l.OpenLoot();

                return(true);
            }

            ShopActivatorTile s = rh.collider.gameObject.GetComponent <ShopActivatorTile>();
            if (s != null)
            {
                canOpenChest = false;

                s.OpenShop();

                return(true);
            }
        }

        return(false);
    }
コード例 #2
0
    public void OnTriggerEnter2D(Collider2D other)
    {
        ParticleManager.Instance.PickUp(transform);
        inv.AddKey(this);

        base.OnTriggerEnter2D(other);
    }
コード例 #3
0
ファイル: GoldKeyPickup.cs プロジェクト: bzhai155/gunsnake
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            if (isKey)
            {
                PlayerInventory.AddKey(1);
            }
            else
            {
                PlayerInventory.AddGold(goldAmount);
            }

            Destroy(gameObject);
        }
    }
コード例 #4
0
    void OnTriggerEnter(Collider c)
    {
        if (c.CompareTag("Player") == false)
        {
            return;
        }

        PlayerInventory inventory = c.GetComponent <PlayerInventory>();

        if (inventory == null)
        {
            return;
        }

        inventory.AddKey();
        Destroy(this.gameObject);
    }
コード例 #5
0
ファイル: Key.cs プロジェクト: safonce/puzzle
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            PlayerInventory inventory = other.GetComponent <PlayerInventory>();
            if (inventory == null)
            {
                return;
            }

            // Check if inventory has space
            if (inventory.IsEmpty())
            {
                // Add to inventory
                inventory.AddKey(this);
                // Destroy key
                Destroy(gameObject);
            }
        }
    }
コード例 #6
0
ファイル: UIManager.cs プロジェクト: bzhai155/gunsnake
    public void AddKeys(int amount)
    {
        ButtonClicked();

        PlayerInventory.AddKey(amount);
    }