Exemple #1
0
    private void FixedUpdate()
    {
        // Check to see if we are jumping over an enemy.
        RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 10, LayerMask.GetMask("Enemies"));

        if (hit.collider != null)
        {
            // We are, store the enemy name
            lastContactObject      = hit.collider.name;
            lastContactObjectScore = hit.collider.GetComponent <GrantPoints>().PointsValue;
        }
        else
        {
            // We are not. Did we just jump an enemy though (lastContact will be set if we did).
            if (lastContactObject != null)
            {
                // Yes we did, consider this a sucessful jump and show the floating text.
                floatingText.CreateFloatingText("+", lastContactObjectScore);
                controller.AddPoints(lastContactObjectScore);
                // Reset the contact object back to null ready for the next jump.
                lastContactObject = null;
            }
        }
    }