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.