Hello Unity3D.I have a question about doing animations while running.How can i make it that my character does a certain animation while running and only while running?For example.My characters do certain punches and kicks while standing still.But when i run i want them to do a special punch,such as a superman much or a special kick,such as a back kick.If anyone knows how i can do this.Can you please tell me how?(I can’t find any scripts for this for some reason).
#pragma strict
var Run:AudioClip;
var rotationSpeed : float = 10;
var walkSpeed : float = 7;
var gravity : float = 50;
var body : Transform;
var length: float;
audio.volume = 0;
private var yRot: float;
function Update () {
var Controller : CharacterController = GetComponent(CharacterController);
var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
var height : Vector3 = transform.TransformDirection(Vector3.up);
if(Input.GetKeyDown("space")){
animation.Play("Jump");
Jump();
}
if(Input.GetAxis("Vertical")||Input.GetAxis("Horizontal")){
if (!animation.IsPlaying("Jump"))
if (!animation.IsPlaying("Jump"))
if(!animation.IsPlaying("Reverse_Crescent"))
if(!animation.IsPlaying("Crescent"))
if(!animation.IsPlaying("Spinning_back_kick"))
if(!animation.IsPlaying("Spinning_back_kick2"))
if(!animation.IsPlaying("Jump_Spinning_Back_Kick"))
if(!animation.IsPlaying("Astral_Ball"))
if(!animation.IsPlaying("Hit1"))
if(!animation.IsPlaying("Are_You_Ready_"))
if(!animation.IsPlaying("Kick_Combo"))
if(!animation.IsPlaying("para_kick"))
if(!animation.IsPlaying("Aerial_Cartwhell"))
if(!animation.IsPlaying("Aerial_Cartwhell_Reverse"))
if(!animation.IsPlaying("Snap_Kick"))
if(!animation.IsPlaying("Thrust_Kick_2"))
if(!animation.IsPlaying("Teleport"))
animation.CrossFade("Run2");
animation["Run2"].speed = walkSpeed/100;
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
audio.Play();
}else{
if (!animation.IsPlaying("Jump"))
if(!animation.IsPlaying("Wing_Chun_Punch"))
if(!animation.IsPlaying("Wing_Chun_Punch_2"))
if(!animation.IsPlaying("Wing_Chun_Punch_3"))
if(!animation.IsPlaying("Wing_Chun_Punch_4"))
if(!animation.IsPlaying("Wing_Chun_Punch_5"))
if(!animation.IsPlaying("Hit1"))
if(!animation.IsPlaying("Oh_Hell_To_The_Fuck_Nah_"))
if(!animation.IsPlaying("Mana_Barrage"))
if(!animation.IsPlaying("Teleport"))
if(!animation.IsPlaying("para_kick"))
if(!animation.IsPlaying("Aerial_Cartwhell"))
if(!animation.IsPlaying("Aerial_Cartwhell_Reverse"))
if(!animation.IsPlaying("Snap_Kick"))
if(!animation.IsPlaying("Snap_Kick_2"))
if(!animation.IsPlaying("Thrust_Kick_2"))
if(!animation.IsPlaying("Hikari_s_Pause"))
if(!animation.IsPlaying("Frisebee_kick_Part_1"))
if(!animation.IsPlaying("Mana_Wave_"))
if(!animation.IsPlaying("Kick"))
if(!animation.IsPlaying("Kick2"))
if(!animation.IsPlaying("Chain_Punches"))
animation.CrossFade("Zen_Fighting_stance_Wing_Chun_");
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
audio.Play();
}
if(Input.GetAxis("Vertical")){
yRot += 10* Input.GetAxis("vertical");
}
}
function LateUpdate(){
// Rotate the Character to match the direction he/she is going
if(Input.GetAxis("Vertical") == 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = 90;//Right sideways running
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = 270;//Left sideways running
}
}else if(Input.GetAxis("Vertical") > 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = -270;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = -90;
}
}else if(Input.GetAxis("Vertical") < 0){
if(Input.GetAxis("Horizontal") == 0){
body.localEulerAngles.y = -180;
}else if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = -180;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = -180;
}
}
}
function Jump(){
gravity = 30;
yield WaitForSeconds(0.2);
gravity = -50;
}