- Home /
Case answered privately by unity development team.
Fruit ninja course
I'm following a course in the udemy website. Earlier my project could not destroy the fruit by making them disappear. Now I succeeded and found that the codes given by the tutorial were not properly written as other students had the same problem. However, now that i added sliced fruits, both the spawned fruits and the sliced fruits just don't appear anymore. I have inserted the link for the project so anyone can download to test it out https://drive.google.com/file/d/1akEMR8eqHrJA0_0Me_B1xwXfvJMkuup-/view?usp=sharing - password not required . The picture has also been inserted so you can see the fruits just refuse to appear.
edit (moved from answer)
I already carefully tested the project. Whether the fruits and fruit cuts are enabled / disabled, the results are the same. I am pasting the spawning codes here. Let me know if you need more codes.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FruitSpawner : MonoBehaviour
{
public GameObject fruit;
public float maxX;
// Start is called before the first frame update
void Start()
{
Invoke("StartSpawning", 1f);
}
public void StartSpawning()
{
InvokeRepeating("SpawnFruitGroups", 1, 6f);
}
public void StopSpawning()
{
CancelInvoke("SpawnFruitGroup");
StopCoroutine("SpawnFruit");
}
public void SpawnFruitGroups()
{
StartCoroutine("SpawnFruit");
}
IEnumerator SpawnFruit()
{
for (int i = 0; i < 5; i++)
{
float Rand = Random.RandomRange(-maxX, maxX);
Vector3 pos = new Vector3(Rand, transform.position.y, 0);
GameObject f = Instantiate(fruit, pos, Quaternion.identity) as GameObject;
f.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15f), ForceMode2D.Impulse);
f.GetComponent<Rigidbody2D>().AddTorque(Random.Range(-20f, 20f));
yield return new WaitForSeconds(0.5f);
}
}
}
Answer by Casiell · Jul 24, 2019 at 06:31 AM
I'm not really eager to download the project, but from the screen you provided it may be possible that your fruit objects are just disabled? If that's not the problem, please paste relevant code (code that spawns your fruit) into your question so we can try to help further
Follow this Question
Related Questions
Missing Component Exception Error 3 Answers
clone object make a new script 0 Answers
Question about instantiate AI 0 Answers
How to have a cloned/duplicated enemy react the same way the original does? 1 Answer