started to learn basic scripting in unity, programming is really not my specialty modeling and texturing would still be my forte but thought might as well learn a bit of basic unity just enough to make simple games
so everything is working fine my only issue is the walk animation wont play if i move the player/character in any other direction
walk animation only plays when i move the player downward but on any other direction the walk animation wont play
#pragma strict
var player: Transform;
var speed: float = 5.0;
var jumpSpeed: float = 3;
var playerWithAnimation: Transform;
var rotateSpeed: float =20;
var grounded: boolean = false;
var maxSlope: float = 60;
function Update()
{
if ( Input.GetAxis(“Horizontal”) > 0.1)
{
playerWithAnimation.animation.CrossFade(“walk”);
player.position += Vector3(speed*Time.deltaTime,0,0);
player.eulerAngles = Vector3(0,90,0);
}
if( Input.GetAxis(“Horizontal”) < -0.1)
{
playerWithAnimation.animation.CrossFade(“walk”);
player.position -= Vector3(speed*Time.deltaTime,0,0);
player.eulerAngles = Vector3(0,-90,0);
}
if ( Input.GetAxis(“Vertical”) > 0.1)
{
playerWithAnimation.animation.CrossFade(“walk”);
player.position += Vector3(0,0,speed*Time.deltaTime);
player.eulerAngles = Vector3(0,0,0);
}
if ( Input.GetAxis(“Vertical”) < -0.1)
{
playerWithAnimation.animation.CrossFade(“walk”);
player.position -= Vector3(0,0,speed*Time.deltaTime);
player.eulerAngles = Vector3(0,-180,0);
}
else
{
playerWithAnimation.animation.Play(“idle”);
}
if(Input.GetButtonDown(“Jump”) grounded )
{
player.rigidbody.velocity.y = jumpSpeed;
}
}
function OnCollisionStay(collision : Collision)
{
for(var contact: ContactPoint in collision.contacts) {
if (Vector3.Angle(contact.normal,Vector3.up) < maxSlope)
grounded = true;
}
}
function OnCollisionExit ()
{
grounded = false;
}