コード例 #1
0
    void OnTriggerStay2D(Collider2D other)
    {
        // Get edge
        EdgeController edgeController = other.GetComponent <EdgeController> ();

        // If hit edge with edge controller
        if (other.CompareTag("Edge") && edgeController)
        {
            moveSpeed = edgeController.changeSpeed(moveSpeed);
        }
    }
コード例 #2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (hitpointController.isDead)
        {
            return;
        }

        // Reverse moving if hit bullets
        if (other.CompareTag("Bullet"))
        {
            moveSpeed *= -1f;
        }

        // Get edge
        EdgeController edgeController = other.GetComponent <EdgeController> ();

        // If hit edge with edge controller
        if (other.CompareTag("Edge") && edgeController)
        {
            moveSpeed = edgeController.changeSpeed(moveSpeed);
        }

        // Collect if hit item
        if (other.tag == "Item")
        {
            // Item name
            Item item = other.GetComponent <Item> ();

            if (item.type == "Star")
            {
                stars += item.amount;
            }

            if (item.type == "Diamond")
            {
                diamonds += item.amount;
            }

            if (item.type == "Hitpoint")
            {
                hitpointController.heal(item.amount);
            }

            // Update UI
            updateResources();

            // Destroy item
            Destroy(other.gameObject);
        }
    }