我有一個遊戲的統一代碼,假設遊戲對象標籤名稱爲「玩家」,假設該遊戲遵循該字符。但我得到一個代碼錯誤,我不知道如何解決它。需要對象引用才能訪問非靜態成員`UnityEngine.GameObject.tag'
錯誤
Assets/Script/CameraRunner.cs(10,32): error CS0120: An object reference
is required to access non-static member `UnityEngine.GameObject.tag'
腳本
using UnityEngine;
using System.Collections;
public class CameraRunner : MonoBehaviour {
void FixedUpdate()
{
if (GameObject.tag == "Player") {
transform.position = new Vector3 (0, transform.position.y + 9f, -10);
}
}
}
爲什麼不直接使用內置的相機SmoothFollow.js腳本或iTween?兩者都符合要求,你只需要稍微修改它。 iTween無處不在。 – ApolloSoftware 2015-02-07 07:45:20
您是否還將腳本附加到主攝像頭,您想要的對象?如果將該腳本附加到相機,那麼GameObject是本地的,它只會檢測本地對象是否標記爲播放器。如果它在玩家身上,那麼對象的位置正在改變。腳本有很多錯誤,特別是沒有足夠的信息來制定適當的響應。 – ApolloSoftware 2015-02-07 07:51:32