错误 cs0246 "The type or namespace name 'Player' could not be found (are you missing a using directi



我正在使用unity创建一个自上而下的2d游戏,我一直得到错误错误cs0246 "类型或名称空间名称'Player'找不到(你是否缺少使用指令或汇编引用?)我好像找遍了所有地方,但我无法修复它,因为我是unity的新手。这是代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour{
public int playerId = 0;
public Animator animator;
public GameObject crosshair7;   
private Player player;
void Awake() {
player = ReInput.players.GetPlayer(playerId);
}
void Update()
{
Vector3 movement = newVector3(Input.GetAxis("MoveHorizontal"),Input.GetAxis("MoveVertical"), 0.0f);
if(player.GetButton("Fire")) {
Debug.Log("Fire");
}
Movecrosshair7();
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Magnitude", movement.magnitude);
transform.position = transform.position + movement * Time.deltaTime;
}
private void Movecrosshair7() {
Vector3 aim = new Vector3(player.GetAxis("AimHorizontal"), player.GetAxis("AimVertical"), 0.0f);
if (aim.magnitude > 0.0f) {
aim.Normalize();
aim *= 0.04f;
crosshair7.transform.localPosition = aim;
}
}
}

您的错误是因为您在另一个名称空间中创建了一个名为Player的类,并且没有导入它。如果你使用的是Visual Studio,你可以在红色下划线的private Player;上添加ctrl+.来自动导入它,否则将名称空间添加到文件的顶部:

using My.Players.Namespace;

我注意到你代码中的另一个错误:

Vector3 movement = newVector3(Input.GetAxis("MoveHorizontal"),Input.GetAxis("MoveVertical"), 0.0f);

应该

Vector3 movement = new Vector3(Input.GetAxis("MoveHorizontal"), Input.GetAxis("MoveVertical"), 0.0f);

相关内容

最新更新