コード例 #1
0
    /**
     * <summary>Filters the collision the player has with world objects.</summary>
     *
     * <param name="collisionEvent">The type of object that was collided with.</param>
     * <param name="obj">The object that was collided with.</param>
     */
    public void Collision(CollisionNotification.CollisionType collisionEvent, GameObject obj)
    {
        switch (collisionEvent)
        {
        case CollisionNotification.CollisionType.CollectableItem:
            app.model.player.heldItems.AddItem(obj);
            app.controller.display.UpdateHotbar();
            obj.SetActive(false);
            break;

        case CollisionNotification.CollisionType.PowerUpItem:
            obj.GetComponent <PowerUpItem>().UseItem();
            break;

        case CollisionNotification.CollisionType.HarmfulItem:
            obj.GetComponent <HarmfulItem>().ActivateHarmingEffect();
            break;

        case CollisionNotification.CollisionType.Objective:
            obj.GetComponent <Objective>().ActivateObjectiveBehavior();
            break;

        default:
            break;
        }
    }
コード例 #2
0
ファイル: PlayerView.cs プロジェクト: Reknotx/SusSpace-2D
    private void OnTriggerEnter2D(Collider2D other)
    {
        //the background layer needs to be ignored with collisions.
        if (other.gameObject.layer == 9)
        {
            return;
        }

        //Barriers and ship are on this layer
        if (other.gameObject.layer == 10)
        {
            app.controller.player.CollidedWithShip();
            return;
        }

        var Object = other.gameObject.GetComponent <Object>();

        CollisionNotification.CollisionType eventType = 0;

        if (Object is HelpfulItem)
        {
            if (Object is CollectableItem)
            {
                eventType = CollisionNotification.CollisionType.CollectableItem;
                //app.controller.AddItemToPlayer(other.gameObject);
            }
            else if (Object is PowerUpItem)
            {
                //PowerUpItem temp = other.gameObject.GetComponent<PowerUpItem>();
                //temp.UseItem();
                eventType = CollisionNotification.CollisionType.PowerUpItem;
            }
        }
        else if (Object is HarmfulItem)
        {
            //Is a harmful item
            //HarmfulItem temp = other.GetComponent<HarmfulItem>();
            //temp.ActivateHarmingEffect();
            eventType = CollisionNotification.CollisionType.HarmfulItem;
        }
        else if (Object is Objective)
        {
            //Is an objective
            //Objective temp = other.GetComponent<Objective>();
            //temp.ActivateObjectiveBehavior();
            eventType = CollisionNotification.CollisionType.Objective;
        }

        app.controller.collisions.Collision(eventType, other.gameObject);
    }