C# Assets/Scripts/cameracoperator.cs(73,45):错误CS0103:名称'hit';在当前上下文中不存在
我正在做一个RTS风格的游戏,我修正了一些错误,现在我有更多的错误。有人能帮忙吗 Assets/Scripts/cameracoperator.cs(71,25):错误CS0131:左侧 赋值的边必须是变量、属性或索引器 Assets/Scripts/cameracoperator.cs(73,45):错误CS0103:名称'hit' 在当前上下文中不存在 这是脚本,任何帮助都会很好C# Assets/Scripts/cameracoperator.cs(73,45):错误CS0103:名称'hit';在当前上下文中不存在,c#,unity3d,C#,Unity3d,我正在做一个RTS风格的游戏,我修正了一些错误,现在我有更多的错误。有人能帮忙吗 Assets/Scripts/cameracoperator.cs(71,25):错误CS0131:左侧 赋值的边必须是变量、属性或索引器 Assets/Scripts/cameracoperator.cs(73,45):错误CS0103:名称'hit' 在当前上下文中不存在 这是脚本,任何帮助都会很好 using UnityEngine; using System.Collections; using Syste
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CameraOperator : MonoBehaviour
{
public Texture2D selectionHighlight = null;
public static Rect Selection = new Rect (0, 0, 0, 0);
private Vector3 StartClick = -Vector3.one;
private static Vector3 moveToDestination = Vector3.zero;
private static List<string> passables = new List<string> () {"Floor"};
private void Update ()
{
CheckCamera ();
CleanUp ();
}
private void CheckCamera ()
{
if (Input.GetMouseButtonDown (0))
{
StartClick = Input.mousePosition;
}
if (Input.GetMouseButtonUp (0))
{
StartClick = -Vector3.one;
}
if (Input.GetMouseButton (0))
{
Selection = new Rect (StartClick.x, InvertMouseY (StartClick.y), Input.mousePosition.x - StartClick.x, InvertMouseY (Input.mousePosition.y) - InvertMouseY (StartClick.y));
if (Selection.width < 0)
{
Selection.x += Selection.width;
Selection.width = -Selection.width;
}
if (Selection.height < 0)
{
Selection.y += Selection.height;
Selection.height = -Selection.height;
}
}
}
float InvertMouseY (float y)
{
return Screen.height - y;
}
private void CleanUp ()
{
if (!Input.GetMouseButtonUp (1)) {
moveToDestination = Vector3.zero;
}
}
public static Vector3 GetDestination ()
{
if (moveToDestination == Vector3.zero)
{
RaycastHit hit;
Ray r = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (r, out hit))
{
while (!passables.Contains(hit.transform.gameObject.name))
{
if (!Physics.Raycast (hit.transform.position, r.direction, out hit))
break;
}
}
}
if(!hit.transform = null)
{
moveToDestination = hit.point;
}
return moveToDestination;
}
}
使用UnityEngine;
使用系统集合;
使用System.Collections.Generic;
公共类摄影机操作员:MonoBehavior
{
公共纹理2D selectionHighlight=null;
公共静态Rect选择=新Rect(0,0,0,0);
私有向量3 StartClick=-Vector3.one;
专用静态向量3 moveToDestination=Vector3.0;
私有静态列表passables=newlist(){“Floor”};
私有无效更新()
{
检查摄像头();
清理();
}
私用照相机()
{
if(Input.GetMouseButtonDown(0))
{
StartClick=Input.mousePosition;
}
if(Input.GetMouseButtonUp(0))
{
StartClick=-Vector3.1;
}
if(Input.GetMouseButton(0))
{
Selection=new Rect(StartClick.x,InvertMouseY(StartClick.y),Input.mousePosition.x-StartClick.x,InvertMouseY(Input.mousePosition.y)-InvertMouseY(StartClick.y));
如果(选择宽度<0)
{
Selection.x+=Selection.width;
Selection.width=-Selection.width;
}
如果(选择高度<0)
{
Selection.y+=Selection.height;
Selection.height=-Selection.height;
}
}
}
浮动鼠标(浮动y)
{
返回屏幕高度-y;
}
私有空间清理()
{
如果(!Input.GetMouseButtonUp(1)){
moveToDestination=Vector3.0;
}
}
公共静态向量3 GetDestination()
{
if(moveToDestination==Vector3.zero)
{
雷卡斯特击中;
光线r=Camera.main.screenpointoray(输入.鼠标位置);
if(Physics.Raycast(r,出击))
{
而(!passables.Contains(hit.transform.gameObject.name))
{
if(!Physics.Raycast(hit.transform.position,r.direction,out-hit))
打破
}
}
}
如果(!hit.transform=null)
{
moveToDestination=点击点;
}
返回目的地;
}
}
我想你只需要在“游戏对象”
中大写“O”。事实上,在第64行,你有hit.transform.gameobject.name
拼写错误,当你学习Someone教程时很容易做出。但是编译器会准确地告诉你错误发生在哪一行。如果你遵循一个有很多拼写错误的教程,你可能想考虑找到一个新的教程。很明显,无论是谁写的,都不是很小心,让你困惑。是的,他们让我困惑,因为我还是个傻瓜。