【发布时间】:2021-08-28 01:40:35
【问题描述】:
我正在使用 unity 创建一个自上而下的 2d 游戏,但我不断收到错误错误 cs0246“找不到类型或命名空间名称'Player'(您是否缺少 using 指令或程序集引用?)它好像我到处都看过,但我无法修复它,因为我是统一的新手。这是代码
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;
}
}
}
【问题讨论】: