我無法讓我的循環工作。我可以讓它工作一次,或者沒有限制。我試圖讓硬幣實例化3次。我不認爲for循環本身是錯誤的,但結構的某處是。循環處於Looted函數中。無法讓我的循環工作
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class corpseKicked : MonoBehaviour {
private Rigidbody2D rb;
private Animator anim;
public GameObject coinPrefab;
public Transform coinSpawn;
private bool kicked = false;
public float timer = 2f;
public GameObject deathFlamePrefab;
private bool flamer;
private bool pay = false;
private bool broke = false;
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
Looted();
}
public void OnTriggerEnter2D(Collider2D other)
{
if (!kicked && other.gameObject.tag == "kickIndicator") {
kicked = true;
transform.Translate (0.0f, .05f, 0.0f);
}
}
public void Looted()
{
if (!pay && kicked) {
pay = true;
Instantiate (coinPrefab, coinSpawn.position, coinSpawn.rotation);
kicked = false;
pay = false;
for (int i = 1; i <= 3; i++)
Debug.Log ("$$$$$$$$$");
}
}
i = 3;'應該是'i <= 3;'。它是「繼續,而這是真實的」,而不是「當這是真的時停止」。 – Blorgbeard
哦對。我忘了把它放回去。我得到了一個點,我試圖隨機組合。謝謝 –
請勿更改您的問題以顯示更正的源代碼。這使它毫無價值。 – abto