示例#1
0
    /// <summary>
    /// Heal the object that needs to heal based on its position and the position of the healing sources.
    /// </summary>
    void Update()
    {
        float health    = healthMechanic.GetHealth();
        float maxHealth = healthMechanic.maxHealth;

        if (health < maxHealth)
        {
            foreach (GameObject healingSource in healingSources)
            {
                // Get the intensity of the light of the healing source.
                Light lightOfHealingSource            = healingSource.GetComponent <Light>();
                float intensityofLightOfHealingSource = lightOfHealingSource.intensity;

                // If the healing source is lit up - heal the object to heal.
                if (intensityofLightOfHealingSource > 0)
                {
                    // Get the position of the healing source and get the distance between it and the object to heal.
                    Vector2 healingSourcePosition = new Vector2(healingSource.transform.position.x, healingSource.transform.position.y);
                    float   distanceBetweenHealingSourceAndObjectToHeal = Vector2.Distance(objectToHeal.transform.position, healingSourcePosition);

                    Debug.Log(distanceBetweenHealingSourceAndObjectToHeal);
                    if (distanceBetweenHealingSourceAndObjectToHeal > minDistance &&
                        distanceBetweenHealingSourceAndObjectToHeal < maxDistance)
                    {
                        healthMechanic.GainHealth(healthToGain);
                    }
                }
            }
        }
    }
示例#2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.tag != "PickUp")
        {
            if (collision.collider.tag == "FallingObject" && collision.collider.gameObject != fallenObject)
            {
                ObjectThatShouldFall fallingObject = collision.collider.gameObject.GetComponent <ObjectThatShouldFall>();
                if (!fallingObject.isOnGround)
                {
                    GameObject  pickUpObject          = collision.collider.gameObject;
                    Rigidbody2D pickUpObjectRigidBody = pickUpObject.GetComponent <Rigidbody2D>();

                    float fallingSpeed = pickUpObjectRigidBody.velocity.x;
                    float weight       = pickUpObjectRigidBody.mass;
                    float gravity      = pickUpObjectRigidBody.gravityScale;

                    if (fallingSpeed > minFallingSpeedDetection)
                    {
                        float lostHealth = fallingSpeed * weight * gravity;
                        lostHealth = Mathf.Floor(lostHealth);

                        float   health       = healthManager.GetHealth();
                        Vector3 healthToLose = new Vector3(lostHealth / 10, 0.0f, 0.0f);

                        healthManager.LoseHealth(healthToLose);

                        fallenObject = collision.collider.gameObject;

                        Debug.Log(fallingSpeed + " " + weight + " " + gravity);
                        Debug.Break();
                    }
                }
            }
        }
    }
示例#3
0
    /// <summary>
    /// Change the intensitiy of the back light based on the health.
    /// </summary>
    public void UpdateIntensityOfBackLight()
    {
        // Get the back light of the wisp and its intensity.
        Light backLight            = transform.parent.GetChild(0).GetComponent <Light>();
        float intensityOfBackLight = backLight.intensity;

        // Get the current health value of the wisp and change it based on the intensity of the light.
        float health = healthManager.GetHealth();

        PlaySound();
        health = Mathf.Floor(health);

        // Change the intensity of the light based on the bullet size.
        intensityOfBackLight = health / 20.0f;

        // Update the back light intensity and the health value of the wisp.
        backLight.intensity = intensityOfBackLight;
    }