Beispiel #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        FiniteBarrel barrel = collision.gameObject.GetComponent <FiniteBarrel>();

        if (barrel != null)
        {
            sSubstance particleInsideBarrel = barrel.CheckParticle();

            if (particleInsideBarrel != null)
            {
                StartFeedBack();
            }
        }

        // Get information about the current collision.
        Particle collectedParticle = collision.GetComponent <Particle>();

        //Escape collisions with ground or other objects or the players is not collecting now.
        if (collectedParticle != null)
        {
            StartFeedBack();
        }
    }
Beispiel #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        bool  success        = false;
        Color collectedColor = Color.black;

        if (collecting == false)
        {
            return;
        }

        FiniteBarrel barrel = collision.gameObject.GetComponent <FiniteBarrel>();

        if (barrel != null)
        {
            sSubstance particleInsideBarrel = barrel.CheckParticle();

            if (particleInsideBarrel != null)
            {
                success = containerToFill.AddParticule(particleInsideBarrel);
                if (success)
                {
                    sSubstance collectedSubstance = barrel.GetParticle();
                    collectedColor = collectedSubstance.particleColor;
                }
                else
                {
                    MessageManager.getInstance().DissplayMessage("There is a problem with this barrel", 1f);
                }
            }
            else
            {
                MessageManager.getInstance().DissplayMessage("There is no substance inside the barrel", 1f);
            }
        }

        // Get information about the current collision.
        Particle collectedParticle = collision.GetComponent <Particle>();

        //Escape collisions with ground or other objects or the players is not collecting now.
        if (collectedParticle != null)
        {
            // Add the substance to the current container sent.
            success = containerToFill.AddParticule(collectedParticle.currentSubstance);

            // Destory particle if collected.
            if (success)
            {
                collectedColor = collectedParticle.currentSubstance.particleColor;
                Destroy(collectedParticle.gameObject);
            }
        }

        if (success)
        {
            particleFeedback.startColor = collectedColor;

            var vel = particleFeedback.velocityOverLifetime;

            PlayerMovement player = FindObjectOfType <PlayerMovement>();

            Vector3 direction = player.transform.position - particleFeedback.transform.position;
            direction = direction.normalized * 10f;

            vel.x = direction.x;
            vel.y = direction.y;
            vel.z = direction.z;


            particleFeedback.Play();
        }
    }