Return Values

Similar to how Parameters allow the caller to pass values into a method, Return Values allow the method to pass a value back to the caller. For example:

using UnityEngine;

public class Example : MonoBehaviour
{
    // void means this method does not return anything.
    private void Awake()
    {
        var counter = 4;
        counter += DoubleValue(6);// DoubleValue returns 12.
        // counter is now 16.
    }

    // int means this method returns an int.
    private int DoubleValue(int value)
    {
        return value * 2;
    }
}

Early Returns

A method with a void return type can use return; statements to end the method early. Doing so can often be very useful for making code easier to read, for example:

No Returns Early returns
private int _CurrentHealth;

private void ApplyDamage(int damage)
{
    if (_CurrentHealth > 0)
    {
        if (damage > 0)
        {
            _CurrentHealth -= damage;
        
            if (_CurrentHealth <= 0)
            {
                _CurrentHealth = 0;
                Debug.Log("Character died.");
            }
        }
        else
        {
            Debug.Log("Damage is negative.");
        }
    }
    else
    {
        Debug.Log("Already dead.");
    }
}
private int _CurrentHealth;

private void ApplyDamage(int damage)
{
    if (_CurrentHealth <= 0)
    {
        Debug.Log("Already dead.");
        return;
    }

    if (damage <= 0)
    {
        Debug.Log("Damage is negative.");
        return;
    }

    _CurrentHealth -= damage;
    
    if (_CurrentHealth <= 0)
    {
        _CurrentHealth = 0;
        Debug.Log("Character died.");
    }
}
This method uses several levels of indentation and takes some effort for anyone reading it to match up each of the else statements with their if to figure out what condition triggers each log message. The problem can get much worse in methods with more conditions to check and more lines between the if and else. This method is much better because each condition is immediately followed by its effects and the return statement clearly indicates that the method won't do anything after logging those messages.