Home > other >  Consult the unity how to access the virtual joystick easyTouch5
Consult the unity how to access the virtual joystick easyTouch5

Time:09-27

Jump key is his own set of "K" key, use the button in the easyTouch changed, you can use,
But the role of mobile is to use
Float h=Input. GetAxis (" Horizontal ");
Vector3 v=GetComponent (). The velocity;
GetComponent (). The velocity=new Vector3 (h * speed, v.y v.z);
,
System default WASD keys, without in their own Settings,
Role orientation is to use the
Float x=1;
If (GetComponent (a). Velocity. X & gt; 0.05 f)
{
X=1;
}
Else if (GetComponent (a). Velocity. X & lt; 0.05 f)
{
X=1;
}
The else
{
X=0;
}
If (x!=0)
{
PlayerGround. Transform. LocalScale=new Vector3 (x, 1, 1);
PlayerJump. Transform. LocalScale=new Vector3 (x, 1, 1);
PlayerDown. Transform. LocalScale=new Vector3 (x, 1, 1);
PlayerDie. Transform. LocalScale=new Vector3 (x, 1, 1);
}
,
Want to ask how to use the joystick to realize the role orientation and idle/walk the state of the switch (ps: is a 2 d horizontal version of the game)




CodePudding user response:

Public void MoveInRightJoyStick (Vector2 weizhi)
{
//print (weizhi. X + ": :" + weizhi. Y);
//if (weizhi. Y!=0 | | weizhi. X!=0) {
//set the role orientation (towards the current coordinates + rocker offset)
//transform. LookAt (new Vector3 (transform) position. X + weizhi. X, the transform. The position. The y, the transform. The position. The z + weizhi. Y));
//animation can get the value of 0 and 1
Float x=(weizhi. X/2) + 0.5 f;
Float y=(weizhi. Y/2) + 0.5 f;

Anim. SetFloat (" Speed ", y);
Anim. SetFloat (" Blend ", x); }
}
This function on any affiliated scene objects, to EasyTouch rocker scripts (ETCJoystick) of MoveEvents OnMove (Vector2); Moving the joystick, every time to call this function;
Pass the rocker value (1 to 1), is also the value of the virtual axis wsad if stopped, just add a function call in MoveEvents OnMoveEnd
Public void MoveInEnd ()
{
Anim. SetFloat (" Speed ", 0.5 f);
Anim. SetFloat (" Blend ", 0.5 f);
}

CodePudding user response:

  • Related