[英]Unity Raycast Warning
I have a Raycasting script, which works, but I keep getting this warning: My VSCommunity Warning Image Line 5: [SerializeField] Camera camera;
我有一个 Raycasting 脚本,它可以工作,但我不断收到此警告: My VSCommunity Warning Image Line 5: [SerializeField] Camera camera;
I don't think the warning is a major problem, but I still want to fix it.我不认为警告是一个主要问题,但我仍然想修复它。
Here is my code:这是我的代码:
public class RaycastCheck : MonoBehaviour
{
Camera camera;
GameObject raycastHitGameObject;
public GameObject GetRaycastHitGameObject()
{
RaycastHit hit;
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
raycastHitGameObject = hit.transform.gameObject;
}
return raycastHitGameObject;
}
private void Awake()
{
camera = GetComponent<Camera>();
}
}
This is simply stating that somewhere in your inheritance chain, a class variable named camera
is already declared.这只是说明在您的 inheritance 链中的某处,已经声明了一个名为camera
的 class 变量。
You can hide the already declared variable by using the new
keyword.您可以使用new
关键字隐藏已经声明的变量。
new Camera camera;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.