您好,欢迎来到爱玩科技网。
搜索
您的当前位置:首页unity2d摇杆控制角色360度转向和移动

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);

    }
   
}


因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- aiwanbo.com 版权所有 赣ICP备2024042808号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务