using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player2Controller : MonoBehaviour
{
public float speed = 5f;
private Rigidbody2D _rigidbody2D;
private Animator _animator;
private Vector2 _lookDirection = Vector2.down;
private Vector2 _currentInput;
private float _x;
private float _y;
void Start()
{
_rigidbody2D = GetComponent<Rigidbody2D>();
_animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
_x = Input.GetAxis("Horizontal");
_y = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(_x,_y);
if(!Mathf.Approximately(movement.x,0.0f) || !Mathf.Approximately(movement.y,0.0f ))
{
_lookDirection.Set(movement.x, movement.y);
_lookDirection.Normalize();
}
_animator.SetFloat("lookX",_lookDirection.x);
_animator.SetFloat("lookY",_lookDirection.y);
_currentInput = movement;
}
private void FixedUpdate()
{
Vector2 position = _rigidbody2D.position;
position += _currentInput* speed * Time.deltaTime;
_rigidbody2D.MovePosition(position);
}
}
是做一个2D人物四个面动画移动 写完运行就显示LookX参数找不到
有没有谁能帮下忙帮我看下啊
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player2Controller : MonoBehaviour
{
public float speed = 5f;
private Rigidbody2D _rigidbody2D;
private Animator _animator;
private Vector2 _lookDirection = Vector2.down;
private Vector2 _currentInput;
private float _x;
private float _y;
void Start()
{
_rigidbody2D = GetComponent<Rigidbody2D>();
_animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
_x = Input.GetAxis("Horizontal");
_y = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(_x,_y);
if(!Mathf.Approximately(movement.x,0.0f) || !Mathf.Approximately(movement.y,0.0f ))
{
_lookDirection.Set(movement.x, movement.y);
_lookDirection.Normalize();
}
_animator.SetFloat("lookX",_lookDirection.x);
_animator.SetFloat("lookY",_lookDirection.y);
_currentInput = movement;
}
private void FixedUpdate()
{
Vector2 position = _rigidbody2D.position;
position += _currentInput* speed * Time.deltaTime;
_rigidbody2D.MovePosition(position);
}
}
是做一个2D人物四个面动画移动 写完运行就显示LookX参数找不到
有没有谁能帮下忙帮我看下啊
