Top.Mail.Ru
Ответы

Помогите с ошибкой CS1061

Assets\Scripts\Player.cs(21,50): error CS1061: 'PlayerInputActions' does not contain a definition for 'Player' and no accessible extension method 'Player' accepting a first argument of type 'PlayerInputActions' could be found (are you missing a using directive or an assembly reference?)

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

public class Player : MonoBehaviour
{

private float movingSpeed = 10f;

private PlayerInputActions playerInputActions;

private Rigidbody2D rb;

private void Awake() {
rb = GetComponent<Rigidbody2D>();
playerInputActions = new PlayerInputActions();
playerInputActions.Enable();
}

private Vector2 GetMovementVector(){
Vector2 inputVector = playerInputActions.Player.Move.ReadValue<Vector2>();

return inputVector;
}

private void FixedUpdate() {
Vector2 inputVector = GetMovementVector();


// Vector2 inputVector = new Vector2(0, 0);

// if (Input.GetKey(KeyCode.W)) {
// inputVector.y = 1f;
// }

// if (Input.GetKey(KeyCode.S)) {
// inputVector.y = -1f;
//}

// if (Input.GetKey(KeyCode.A)) {
// inputVector.x = -1f; // Исправлено направление движения по оси X
// }

// if (Input.GetKey(KeyCode.D)) {
// inputVector.x = 1f;
// }

Debug.Log(inputVector);

rb.MovePosition(rb.position + inputVector * (movingSpeed * Time.fixedDeltaTime));
}
}

1
 помогите с ошибкой 
По дате
По рейтингу
Аватар пользователя
Оракул
11мес
123456789
 private void Awake() {  
    rb = GetComponent<Rigidbody2D>();  
    playerInputActions = new PlayerInputActions(); 
    playerInputActions.Player.Enable(); // Включаем конкретный Action Map 
} 
 
private Vector2 GetMovementVector(){ 
    return playerInputActions.Player.Move.ReadValue<Vector2>(); 
} 

Если проблема все еще сохраняется, проверьте следующее:

1. Убедитесь, что ваш Input Action Asset правильно настроен и сохранен.
2. Попробуйте закрыть и снова открыть Unity, иногда это помогает обновить сгенерированные классы.
3. Проверьте, нет ли ошибок в консоли Unity, которые могут указывать на проблемы с Input System.