**EDIT:**
Your game is 2D or 3D , your trying to make something like zelda or pokemon?
You are mixing lots of stuff there. transform.position it's equal to (x,y,z) or Vector3 and when you do transform.Translate() you are calling a function So you are adding a function to a Vector3.
And where are you putting al this code? on function Update()?
Try with this code:
private var myScale : float;
function Start(){
myScale = transform.localScale.x;
}
function Update(){
// MOVE LEFT AND RIGHT
if(Input.GetAxis("Horizontal")){
var AxisValue :float = Input.GetAxis("Horizontal");
transform.Translate(Vector3.right * AxisValue *speed);
if(AxisValue > 0){
transform.localScale.x = myScale ;
} else {
transform.localScale.x = -myScale ;
}
}
// MOVE UP AND DOWN
if(Input.GetAxis("Vertical")){
transform.Translate(Vector3.up * Input.GetAxis("Vertical")*speed)
}
}
I don't completly understand how you are using this code but you are using always transform.forward , if it's an up and down game don't you have to use transform.up or down, etc.?
To flip your player you can do
var myScale = transform.localScale;
if (Input.GetKey (KeyCode.LeftArrow))
{
transform.localScale = -myScale; // FLIP to the opposite direction
}
if (Input.GetKey (KeyCode.RightArrow))
{
transform.localScale = myScale; // FLIP to the original direction
}
//For moving i like to use .Translate
transform.Translate(Vector3.up * Time.deltaTime * speed)
// Use Vector3.up , Vector3.forward, Vector3.right, Vector3.down , etc
↧