Public class PlayerMovement: MonoBehaviour
{
Rigidbody2D rb.
Collider2D coll.
Animator anim.
Public float speed;
Vector2 movement;
Private void Awake ()
{
Rb=GetComponent
}
Private void the Update ()
{
The Movement ();
SwitchAnim ();
}
Void Movement ()//move
{
Movement. X=Input. GetAxisRaw (" Horizontal ");
Movement. Y=Input. GetAxisRaw (" Vertical ");
Rb. MovePosition (rb. Position + speed movement * * Time. DeltaTime);
}
Void SwitchAnim ()/switch/animation
{
If (movement!=Vector2. Zero)//that Horizontal to 0, keeping movment values to switch the idle animation blend tree
{
Anim. SetFloat (" horizontal ", movement. X);
Anim. SetFloat (" vertical ", movement. Y);
}
Anim. SetFloat (" speed ", the movement magnitude);//magnitude can also use sqrMagnitude specific reference Api can be the default return value forever & gt;=0
}
}
CodePudding user response:
Can be done with rayCodePudding user response:
1. To get a plane can click2. To determine whether a state of control can click in the update status
String m_strClickArea_Tag="ClickArea";
If (m_isChoiceGameObject)//clickable state
{
If (Input. GetMouseButtonDown (0))
{
M_isChoiceGameObject=false;//points after the reset to not click
Vector3 touchPos=Input. MousePosition;
Camera curCamera=m_mainCamera;
If (curCamera!=null)
{
TouchPos. Z=curCamera. NearClipPlane;
TouchPos=curCamera. ScreenToWorldPoint (touchPos);
Vector3 dir=touchPos - curCamera. The transform. The position;
RaycastHit [] hits=Physics. RaycastAll (curCamera. The transform. The position, dir);
For (int I=0; I & lt; Hits. Length; I++)
{
RaycastHit hit=hits [I];
If (hit.transform.Com pareTag (m_strClickArea_Tag))
{
//if (EventSystem. Current. IsPointerOverGameObject ())
//{
//return;
//}
//the world coordinates,
Vector3 Vector3=new Vector3 (hit) point) x, 0, hit the point. The z);
//screen coordinates
Vector3 vector3Screen=curCamera. WorldToScreenPoint (Vector3);