unity2d摇杆控制角色360度转向和移动

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float speed;
    new private Rigidbody2D rigidbody;
    private Animator animator;
    
    public Joystick joystick;
    
    void Start()
    {
        rigidbody = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
        
    }

    void Update()
    {
        Vector2 moveVec = new Vector2(joystick.Horizontal,
     joystick.Vertical);


        Vector3 lookVec = new Vector3(joystick.Horizontal,
         joystick.Vertical, 4000);

        transform.rotation = Quaternion.LookRotation(lookVec, Vector3.forward);
        transform.Translate(moveVec * Time.deltaTime * speed, Space.World);
        

        //if (input != Vector2.zero)
        //{
        //    animator.SetBool("isMoving", true);
        //    stopX = inputX;
        //    stopY = inputY;
        //}
        //else
        //{
        //    animator.SetBool("isMoving", false);
        //}
        //animator.SetFloat("InputX", stopX);
        //animator.SetFloat("InputY", stopY);

    }
   
}


你可能感兴趣的:(c#,unity,动画)