Various Code errors, found X was expecting Y, missing ";", and "can't declair functions on the fly"

My code, as good as i can do, probably not the best but ya’know.
anyway, Its giving me grief in the console in Unity, telling me to swap ='s for :'s ect.
So can someone have a look see whats up? Thanks!

I get these errors: (17,18) expecting(, found ‘OnMouseOver’.
(19,9) Unexpected token: if.
( 21,20) expecting :, found ‘=’.

var maxDist : float;
var forceStrength = 10.0;
var reverseStrength = -10.0;
private var applyForce = false;
private var reverseForce = false;


function Awake()
{
    var hit : RaycastHit;
    if(Physics.Raycast(transform.position, transform.forward, hit, maxDist))
    {
        if(hit.transform.tag == "Dynamic")
        {
            function OnMouseOver();
            {
                if(Input.GetMouseButton(0));
                {
                    applyForce = true
                }
                else
                {
                    applyForce = false;
                }
                if(Input.GetMouseButton(0))
                {
                    reverseForce = true;
                } 
                else 
                {
                    reverseForce = false;
                }
            }
        }
    
        function OnMouseExit()
        {
            applyForce = false;
            reverseForce = false;
        }
    }
}

Thanks.

From what I can tell, you are defining the OnMouseOver() function inside of Awake() which of course doesn’t work. Additionally there’s a semicolon at the end of this line:

function OnMouseOver();

And from the looks of your code it seems to me, that the parentheses got wrong.

All those things confuse the compiler and lead to stupid error messages like the one you mentioned.
So try to go through your code again and fix parentheses, semicolons and the order of stuff and you should be fine.

You can’t declare functions on the fly. This is not a dynamic scripting language, it’s a compiled language. UnityScript works way different to the JavaScript you might know from website developing.

I guess you want something like that:

var maxDist : float;
var forceStrength = 10.0;
var reverseStrength = -10.0;
private var applyForce = false;
private var reverseForce = false;


function OnMouseOver()
{
    var hit : RaycastHit;
    if(Physics.Raycast(transform.position, transform.forward, hit, maxDist))
    {
        if(hit.transform.tag == "Dynamic")
        {
            applyForce = Input.GetMouseButton(0);
            reverseForce = Input.GetMouseButton(0);
        }
    }
}

function OnMouseExit()
{
    applyForce = false;
    reverseForce = false;
}