我无法让我的循环工作。我可以让它工作一次,或者没有限制。我试图让硬币实例化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