//当进入决斗模式时,判断玩家是否移动摇杆
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved){
Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
RaycastHit hit;
if(Physics.Raycast (ray, out hit, 1000)){
print(hit.transform.name.ToString());
if(hit.transform.name=="rockerColorUp"){
//获取手势移动的速度
Vector2 touchDeltaPosition= Input.GetTouch(0).deltaPosition;
float distance=Mathf.Sqrt(Mathf.Pow(touchDeltaPosition.x,2f)+Mathf.Pow(touchDeltaPosition.y,2f));
velocity=Mathf.Abs(distance/Time.deltaTime);
velocity=Mathf.Sqrt(velocity)/10000;
//根据手势移动速度决定能量条的增长,同时能量条有一个固定的减速
GameSetting.energyBarValue+=(velocity-GameSetting.BarSpeedDown[GameSetting.CompetitorNow.id-1]);
GameSetting.energyBarValue=1;
energyBar.UpdateBar_MJM(GameSetting.energyBarValue,false)
//控制摇杆的移动
if(target){
rocker.transform.Rotate(0,0,-500*Time.deltaTime);
}
else{
rocker.transform.Rotate(0,0,500*Time.deltaTime);
}
if(rocker.transform.localEulerAngles.z<=340&&rocker.transform.localEulerAngles.z>=20&&target){
target=false;
rocker.transform.localEulerAngles=new Vector3(0,0,340);
}
if(rocker.transform.localEulerAngles.z>=20&&rocker.transform.localEulerAngles.z<=340&&!target){
target=true;
rocker.transform.localEulerAngles=new Vector3(0,0,20);
}
}
}
}
else{
//在能量条值大于0时,且玩家没有手势动作时,能量条有一个固定的减速
if(GameSetting.energyBarValue>=0){
GameSetting.energyBarValue-=GameSetting.BarSpeedDown[GameSetting.CompetitorNow.id-1];
energyBar.UpdateBar_MJM(GameSetting.energyBarValue,false);
}
rocker.transform.localEulerAngles=new Vector3(0,0,0);
}
通过滑动手势控制摇杆移动并且通过移动的速度控制能量条的增长 Unity
最新推荐文章于 2020-04-30 23:03:21 发布