我試圖讓鼠標放下工作,我找到了一個例子,但它不工作 這是我的錯誤 Assets/scripts/onclickx.js(13,5):BCE0044 :期待EOF,找到'}'。閱讀鼠標點擊InputsGetMouseDown with Unityscript
這是我的代碼
import UnityEngine.UI;
import UnityEngine.EventSystems;
if(Input.GetMouseDown(0){
// Whatever you want it to do.
ScoreSystem.drinks -= 1;
mySlider = GameObject.Find("water").GetComponent(UnityEngine.UI.Slider);
counter.water = counter.water += 10
mySlider.value = counter.water;
}
這對counter.js
import UnityEngine.UI;
var mySlider: UnityEngine.UI.Slider;
var water = 90;
function Start() {
// substitute 'sliderName' with the literal name
// of your slider as it appears in the hierarchy:
mySlider = GameObject.Find("water").GetComponent(UnityEngine.UI.Slider);
mySlider.value = water;
}
function OnTriggerEnter(other : Collider)
{
Destroy(gameObject);
ScoreSystem.drinks += 1;
mySlider.value += 10;
// insert desired variable here in place of 'n'
// slider will automagically adjust to display new value
}
腳本,這是
static var myScore = 0;
static var score = 0;
static var money = 0;
static var level = 0;
static var drinks = 0;
public var guiSkin : GUISkin;
function OnGUI()
{
GUI.skin = guiSkin;
GUI.contentColor = Color.green;
GUI.Label(Rect((Screen.width/2) - 60,15, 200, 30), "Score: " + score);
GUI.Label(Rect((Screen.width/2) - 60,30, 200, 30), "Money: " + money);
GUI.Label(Rect((Screen.width/2) - 60,42, 200, 30), "Level: " + level);
GUI.Label(Rect((Screen.width/2) - -320,25, 200, 30), "Drinks: " + drinks);
}
回答完最後一個問題後,我忘了告訴你一些事情。 UnityScript/Javascript不再支持(https://stackoverflow.com/a/45536613/3785314)。編譯器很快就會被移除。你必須[學習](https://unity3d.com/learn/tutorials/s/scripting)並開始使用C#。 – Programmer
至於你的問題,你需要在'{'之前添加另一個')。此外,'if'語句中的代碼應該在函數內部。它現在不在函數內部。 – Programmer
@Programmer請給我舉個例子 – ines