第12行和第22行的語法錯誤似乎沒有任何缺失/額外括號,所以它困擾我是什麼導致這些錯誤在我的更新功能。理想情況下,我希望程序在重新加載8秒之前能夠啓動四次。期望{和EOF發現}團結Javascript
#pragma strict
var Bullet : Transform;
var Spawn : Transform;
var amountOfShots = 4;
function Update() {
\t if (Input.GetKeyDown("r") {
Reload(); //Calls the reload function
}
if (Input.GetButtonDown("Fire1")) {
//Fires on left click
Shoot();
amountOfShots --;
//Calls shoot function and removes one shot from amountOfShots
}
}
function Shoot() {
var pel = Instantiate(Bullet, Spawn.position, Spawn.rotation);
pel.rigidbody.AddForce(transform.forward * 6000);
//instantiates bullet at spawn point and adds a force to propel the bullet forward
if (amountOfShots <= 0) {
Debug.Log("No ammo left in magazine");
//Tells player if there is not enough ammo to fire
}
}
function OnReload()
"setTimeout(8000, 3000)"
//Waits 8 seconds while reloading
function Reload()
{
amountOfShots = 4;
//resets amount of shots to 4
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
謝謝你們解決問題。代碼似乎工作正常(沒有語法錯誤),但射擊功能似乎並沒有實例化實際的子彈對象。在統一引擎中,它只是產生了一個看不見的子彈(克隆)。任何人都知道爲什麼會這樣?項目中有一個實際的子彈預製件 – DarkestDreams