|
Java Code - Movement
[Back]
Code:
//3D & 2D Movement
var speed : float = 10; //Variables
function Update () {
//Before you can use the ("w, s, a, d or any arrows key")) you much go to Edit, Project Setting and then hit input
//and up the Axes size, this will let us add new one,
//we going to change the name of the new one [but right now it should has the same name has the last
//one on top of it] what we want to do next is change the [Positive Button] to any key you want.
//What keys pressed is down
if (Input.GetButton ("w"))
{
transform.Translate(Vector3(0,speed,0) * Time.deltaTime);
}
//The (0,speed,0) Is really the (X,Y,Z) and the Speed is the [Variables] we made on top,
//if you put a - by speed it go the other way.
if (Input.GetButton ("s"))
{
transform.Translate(Vector3(0,-speed,0) * Time.deltaTime);
}
if (Input.GetButton ("a"))
{
transform.Translate(Vector3(-speed,0,0) * Time.deltaTime);
}
if (Input.GetButton ("d"))
{
transform.Translate(Vector3(speed,0,0) * Time.deltaTime);
}
}
var speed : float = 10; //Variables
function Update () {
//Before you can use the ("w, s, a, d or any arrows key")) you much go to Edit, Project Setting and then hit input
//and up the Axes size, this will let us add new one,
//we going to change the name of the new one [but right now it should has the same name has the last
//one on top of it] what we want to do next is change the [Positive Button] to any key you want.
//What keys pressed is down
if (Input.GetButton ("w"))
{
transform.Translate(Vector3(0,speed,0) * Time.deltaTime);
}
//The (0,speed,0) Is really the (X,Y,Z) and the Speed is the [Variables] we made on top,
//if you put a - by speed it go the other way.
if (Input.GetButton ("s"))
{
transform.Translate(Vector3(0,-speed,0) * Time.deltaTime);
}
if (Input.GetButton ("a"))
{
transform.Translate(Vector3(-speed,0,0) * Time.deltaTime);
}
if (Input.GetButton ("d"))
{
transform.Translate(Vector3(speed,0,0) * Time.deltaTime);
}
}