【发布时间】:2019-09-14 19:39:07
【问题描述】:
我正在统一制作我的第一个游戏,但出现了这个错误我不知道我是否可以使用“使用”标签来解决这个问题,我不知道是哪个
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour
{
public LayerMask ourMovmentMask;
Camera cam;
PlayerMotor motor;
// Start is called before the first frame update
void Start()
{
cam = Camera.main;
motor = GetComponent<PlayerMotor>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100, ourMovmentMask))
{
Debug.Log("we hit " + hit.collider.name + " " + hit.point);
// move player to what we hit
// stop focusing any objects
}
}
}
}
【问题讨论】:
-
你需要将你的类封装在一个命名空间中...
-
您可以将 using 语句放在命名空间 See this StackOverflow question asking about the issue 内。很多时候,在 Unity 中创建的脚本不会包含命名空间。
-
@TheIncorrigible1 ...我不知道为什么这么多人赞成,但你在说什么?您需要在命名空间中封装某些东西的唯一情况是,当您想要隐藏它或者同名的东西已经存在于另一个命名空间中时。这里的问题是甚至找不到类型......
-
@Eliasar 问题似乎不在于 where 放置
using语句,而是因为缺少PlayerMotor类型甚至找不到using语句(无论是否在命名空间内)或者它不存在可能是由于编译器错误等 -
你能告诉我们
PlayerMotor是什么吗?你实现了这个还是做了它,例如来自下载的资产?如果您将所有关于motor的行注释掉,Unity 控制台中是否还有其他编译器错误?