Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Box2D is only a physics engine, im not sure what you need!?
[color=green]// This is the name and class of our "walkScript"[/color]
public class walkScript : MonoBehaviour
{
[color=green]// before we do anything we should set up some variables (public will make it viewable in the Inspector and you can simply change the value there. float is the type so we can use numbers with decimals and you need to at a "f" behind the number to make it clear)[/color]
public float moveSpeed = 10f;
[color=green]// Function: "Update" runs every frame in the game (void just says we have a new function here)[/color]
[color=lightblue]void[/color] Update ()
{
[color=green]// this sets up our movementspeed (Horizontal and Vertical are by default the arrow keys. but you could easily change them in the settings) we multiply our moveSpeed with the direction we hit and multiply it with smoothDeltaTime so we get a smooth movement over time[/color]
float moveForward = moveSpeed * Input.GetAxis("Horizontal") * Time.smoothDeltaTime;
[color=green]// This will make our Object move forward (Vector3.forward gives us the direction, here it's in front of our tank)[/color]
transform.Translate(Vector3.forward * moveForward);
[color=green]// checks if we press the button (0 = no action, -1 & +1 = button pressed (right & left))[/color]
if(Input.GetAxis("Horizontal") != 0)
{
[color=green]// if it's not 0 we press a button, therefore we need some kind of animation
// play your walk animation here[/color]
}
else
{
[color=green]// play your idle animation here[/color]
}
}
}
