J'ai du mal à faire fonctionner ma boucle for. Je peux soit le faire fonctionner une fois, soit sans limite. J'essaie d'obtenir des pièces à instancier jusqu'à 3 fois. Je ne pense pas que la boucle for elle-même est fausse, mais la structure est quelque part. La boucle est dans la fonction Butin.Je n'arrive pas à faire fonctionner ma boucle for
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;' devrait être 'i <= 3;'. C'est "continuer pendant que c'est vrai", pas "arrêter quand c'est vrai". – Blorgbeard
oh à droite. sry j'ai oublié de le remettre. Je suis arrivé à un point où j'essayais des combinaisons aléatoires. merci –
Ne changez pas votre question pour montrer le code source corrigé. Cela le rend inutile. – abto