Help tidying/neatening up my script

I’m kinda new to Unity scripting and I’m looking for pointers earlier on so I hopefully wont pick up bad habbits.

In the little project im messing aroudn with I have a FPS, and a cube representing a gun, and I also have a few boxes, some have a tag JumpTo.

The idea I wanted to make is if the FPS is close enough to the JumpTo tagged boxes it will display a image so the player knows he’s close enough and he can port onto them. The script ive come up with what seems to work so far is this.

function Update () {
    var hit: RaycastHit;
    if (Physics.Raycast(Gun.transform.position, Gun.transform.forward, hit)){
    	if (hit.transform.tag == 'JumpTo')
    	{
    		Text.guiTexture.enabled = true;
    		
    		if (Input.GetButtonDown("Fire1"))
    		{
    			var distance = Vector3.Distance (Player.transform.position, hit.transform.position);
    			
    			if (distance > 17)
    			{
    				Debug.Log('Too far to jump!');
    			} 
    			else
    			{
    				Player.transform.position.y = hit.transform.position.y+5;
    				Player.transform.position.x = hit.transform.position.x;
    				Player.transform.position.z = hit.transform.position.z;
    			}
    		}
    	}
    	else
    	{
    		Text.guiTexture.enabled = false;
    	}
    }
}

However, it looks and seems really messy. I’m just curious as to what I could change to make it better and less messy.

It’s not too bad, yet… if you’re that worried about it you could always make another script and split the functionality, of course this would make it more difficult if you want to communicate between them.

function Update () {
    var hit: RaycastHit;
    if(Physics.Raycast(Gun.transform.position, Gun.transform.forward, hit)){
        if(hit.transform.tag == 'JumpTo'){
            Text.guiTexture.enabled = true;
            
            if(Input.GetButtonDown("Fire1")){
                var distance = Vector3.Distance(Player.transform.position,hit.transform.position);
                
                if(distance < 17)
                    Player.transform.position = hit.transform.position+(Vector3.up*5);
            }
        }else
            Text.guiTexture.enabled = false;
    }
}

A lot of this is personal preference, but I like to consolidate everything and brackets taking up space bothers me, but things like lines 18-20 are redundant and can easily be compressed. I’m pretty sure that will work for ya…

Good to know it’s not as bad as I was expecting :). Also thanks for the tip about lines 18-20.