Assets / Scripts / CameraOperator.cs(73,45):错误CS0103:名称`hit'在当前上下文中不存在

时间:2014-10-30 13:12:26

标签: c# unity3d

我正在制作一个RTS风格的游戏,我修复了一些错误,现在我遇到了更多的错误。有人可以帮忙吗?

  

Assets / Scripts / CameraOperator.cs(71,25):错误CS0131:左手   作业的一面必须是变量,属性或索引器

     

Assets / Scripts / CameraOperator.cs(73,45):错误CS0103:名称`hit'   在当前上下文中不存在

这是脚本,任何帮助都会很棒。

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

1 个答案:

答案 0 :(得分:0)

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