Unity3D多个动画同时存在时间的控制代码
var player_:GameObject;var run_Speed_:float=3.0;
var rotate_Speed_:float=3.0;
var time_:float;
var jump_Speed:float=8.0f;
var jump_Bool:boolean=true;
//---------DaZhaoController
var dazhao_Time:float;
var dazhao_t_Bool:boolean=false;
var dazhao_All_Controlelr:boolean=true;
//---------
//________________________________________________________move jump
//var jumpSpeed : float = 4.0;
//var gravity : float = 10.0;
//______________________________________________________
var cc_ : CharacterController ;
var animation_:GameObject;
//------j k key controller
var jk_Time:float;
var jk_t_Bool:boolean=false;
var jk_All_Controller:boolean=true;
//----------
//------Jump controller
var Jump_Time:float;
var Jump_t_Bool:boolean=false;
var Jump_All_Controller:boolean=true;
//----------
//跳跃的相对控制
private var moveDirection : Vector3 = Vector3.zero;
function OnGUI() {
}
//--------------_____________________________________
function Start()
{
player_=GameObject.Find("Male_A1");
animation_=GameObject.Find("Bip01");
var run_=player_.animation["Run"];
run_.wrapMode=WrapMode.Loop;
player_.animation["ShenLanYao"].wrapMode=WrapMode.Loop;
player_.animation["FuXiongYangWang"].wrapMode=WrapMode.PingPong;
// player_.animation["YueShuangTui"].wrapMode=WrapMode.Once;
player_.animation["QianBuCeTi"].wrapMode=WrapMode.Once;
player_.animation["DaZhao"].wrapMode=WrapMode.Once;
player_.animation["ZhongQuan"].wrapMode=WrapMode.Once;
player_.animation["YouTuiHuiTi"].wrapMode=WrapMode.Once;
//space
player_.animation["YueShuangTi"].wrapMode=WrapMode.Default;
player_.animation["GaoKongLuoXia"].wrapMode=WrapMode.Once;
//BaoZha_=GameObject.Find("BaoZ");
//BaoZha_.SetActiveRecursively(false);
}
function Update () {
cc_ = GetComponent(CharacterController);
//-jump-------------------------
/*if (cc_.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
//我们着地了,所以直接通过轴重新计算move direction。
moveDirection = Vector3(0, 0,0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= 8.0;
if (Input.GetKeyDown(KeyCode.Space) ) {
moveDirection.y = 5;
player_.animation.CrossFade("YueShuangTi");
}
}
// Apply gravity
//应用重力。
moveDirection.y -= 8 * Time.deltaTime;
// Move the controller
//移动控制器。
cc_.Move(moveDirection * Time.deltaTime);*/
//-jump-------------------------
player_.animation["QianBuCeTi"].layer=1;
player_.animation["ZhongQuan"].layer=1;
player_.animation["DaZhao"].layer=1;
player_.animation["YueShuangTi"].layer=2;
//player_.animation["FuXiongYangWang"].layer=1;
//player_.animation["Run"].layer=1;
//player_.animation["DaZhao2"].layer=1;
//--全部设置为固定-攻击动作
/*if(!player_.animation.IsPlaying("QianBuCeTi"))
{
if(!player_.animation.IsPlaying("ZhongQuan"))
{
if(!player_.animation.IsPlaying("DaZhao"))
{
}
}
}*/
if(dazhao_All_Controlelr)//dazhao controller
{
if(!player_.animation.IsPlaying("QianBuCeTi"))
{
if(!player_.animation.IsPlaying("ZhongQuan"))
{
//--------------------------------------jump controller------------------------------------------
if(Jump_All_Controller==true)
{
if(cc_.isGrounded)
{
//moveDirection=cc_.transform.position;
//moveDirection*=8.0;
if(Input.GetKeyDown(KeyCode.Space))
{
Jump_t_Bool=true;
moveDirection.y=8;
player_.animation.CrossFade("YueShuangTi");
//cc_.transform.position.y=Mathf.Lerp(cc_.transform.position.y,cc_.transform.position.y+10,0.05);
print("sddasd");
}
}
}
moveDirection.y-=20*Time.deltaTime;
cc_.Move(moveDirection*Time.deltaTime);
//--------------------------------jump time controller------
if(Jump_t_Bool)
{
Jump_Time+=Time.deltaTime;
if(Jump_Time<1.4)
{
Jump_All_Controller=false;
}
else if(Jump_Time>1.4)
{
Jump_t_Bool=false;
Jump_All_Controller=true;
}
//print(Jump_Time);
}
else if(Jump_t_Bool==false)
{
Jump_Time=0;
}
//--------------------------------jump time controller------
//--------------------------------------jump controller------------------------------------------
if(Input.GetKey(KeyCode.W))
{
cc_.SimpleMove(cc_.transform.TransformDirection(Vector3.forward)*3);
//print(cc_.transform.TransformDirection(Vector3.forward)*3);
}
if(Input.GetKey(KeyCode.S))
{
cc_.transform.Rotate(0,Mathf.Lerp(0,-360,Time.deltaTime),0);
cc_.SimpleMove(cc_.transform.TransformDirection(Vector3.forward)*-3);
}
if(Input.GetKey(KeyCode.A))
{
cc_.transform.Rotate(0,-1,0);
}
if(Input.GetKey(KeyCode.D))
{
cc_.transform.Rotate(0,1,0);
}
if(Input.GetKeyDown(KeyCode.W))
{
player_.audio.volume =Main_Window.scrollSetSound;
player_.audio.Play();
}
if(Mathf.Abs(Input.GetAxis("Vertical"))>0.1||Mathf.Abs(Input.GetAxis("Horizontal")))
{
player_.animation.CrossFade("Run");
// print("da");
}
else
{
player_.animation.CrossFade("FuXiongYangWang",0.5);
}
}
}
//----------------------------------------Acttack controller-----------------------------------------------
if(jk_All_Controller)
{
if(!player_.animation.IsPlaying("YueShuangTi"))
{
if(Input.GetKeyDown(KeyCode.K))
{
jk_t_Bool=true;
player_.animation.CrossFade("QianBuCeTi");
//BaoZha_.SetActiveRecursively(true);
//Instantiate(BaoZha_,BaoZha_.transform.position,BaoZha_.transform.rotation);
}
if(Input.GetKeyDown(KeyCode.J))
{
jk_t_Bool=true;
player_.animation.CrossFade("ZhongQuan");
}
}
}
if(jk_t_Bool)
{
jk_Time+=Time.deltaTime;
if(jk_Time<0.4)
{
jk_All_Controller=false;
}
else if(jk_Time>0.5)
{
jk_t_Bool=false;
jk_All_Controller=true;
}
}
else if(jk_t_Bool==false)
{
jk_Time=0;
}
//----acttack controller
//----------------------------------------Acttack controller-----------------------------------------------
}
//cc_.transform.Rotate(0,Input.GetAxis("Horizontal")*rotate_Speed_,0);
//--------------------------------------------------dazhao controller------------------------------------------
if(!player_.animation.IsPlaying("YueShuangTi"))
{
if(Input.GetKeyDown(KeyCode.J)&&Input.GetKeyDown(KeyCode.K))
{
if(Power.powerValue>33) //judgepowerValue
{
player_.animation.CrossFade("DaZhao");
dazhao_t_Bool=true;//dazhao js controller
dazhao_All_Controlelr=false;
//cc_.Move(Vector3(0,1*Time.deltaTime,0));
}
}
}
if(dazhao_t_Bool)
{
dazhao_Time+=Time.deltaTime;
if(0.5<dazhao_Time&&dazhao_Time<1.2)//go
{
cc_.SimpleMove(cc_.transform.TransformDirection(Vector3.forward)*6);
}
//dazhao_Bool=true;
else if(dazhao_Time>4.8&&dazhao_Time<5.2)//back
{
cc_.SimpleMove(cc_.transform.TransformDirection(Vector3.forward)*-12);
}
else if(dazhao_Time>5.2)//false
{
dazhao_t_Bool=false;
dazhao_All_Controlelr=true;
}
}
else if(dazhao_t_Bool==false)
{
dazhao_Time=0;
}
//--------------------------------------------------dazhao controller------------------------------------------
}
function Do()
{
yield WaitForSeconds (5.0);
}
感谢楼主的无私分享!{:soso__11402694654016840197_7:} 谢谢分享! 楼主是超人 好帖就是要顶 难得一见的好帖 很好哦 不错不错 楼主是超人 好帖就是要顶
页:
[1]