我正在製作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;
}
}
我建議你開始檢查拼寫錯誤並更好地調試你的代碼。你在過去的12個小時裏詢問了4個問題,都是簡單的錯別字。 – 2014-10-30 14:26:01
當你跟隨someones教程時,錯別字很容易製作。 – 2014-10-30 14:29:56
但編譯器告訴你_exactly_錯誤發生在哪一行。如果你正在學習一個包含很多拼寫錯誤的教程,你可能需要考慮尋找一個新的教程。顯然誰寫的不是很小心,而且讓你感到困惑。 – 2014-10-30 14:31:48