2014-10-30 66 views
-1

我正在制作RTS风格的游戏,现在我修正了一些错误,我得到了更多错误。有人可以帮忙吗?资产/脚本/ CameraOperator.cs(73,45):错误CS0103:当前上下文中不存在名称'hit'

资产/脚本/ CameraOperator.cs(71,25):错误CS0131:左手的分配的 侧必须是一个变量,属性或索引

资产/脚本/ CameraOperator的.cs(73,45):错误CS0103:名称'打” 不会在目前情况下

存在这里是脚本,和任何帮助将BR很大。

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; 
    } 
} 
+0

我建议你开始检查拼写错误并更好地调试你的代码。你在过去的12个小时里询问了4个问题,都是简单的错别字。 – 2014-10-30 14:26:01

+0

当你跟随someones教程时,错别字很容易制作。 – 2014-10-30 14:29:56

+1

但编译器告诉你_exactly_错误发生在哪一行。如果你正在学习一个包含很多拼写错误的教程,你可能需要考虑寻找一个新的教程。显然谁写的不是很小心,而且让你感到困惑。 – 2014-10-30 14:31:48

回答

0

我认为您只需要在“gameobject”中大写“O”即可。实际上,在第64行,你有hit.transform.gameobject.name

+0

谢谢你修正了一些错误。 – 2014-10-30 13:28:11

相关问题