Hi my old code had instantiation of my special scripts when it was targeted to a regular cube as a holder, but i added in artwork for the new bonuses that are supposed to spawn and made them prefabs then selected each prefab for each gameojbect declaration. But now when my ball hits the blocks no bonuses ever spawn. It used to when i just used a regular cube as a placeholder for the gameobject target and also added rigidbodies and the script that needed to be attached. But now it doesn’t work at all with my new scripts, no bonuses spawn when a block is hit, Can someone tell me whats wrong. Is there a difference in instantiating a prefab as opposed to a gameobject cube? The Prefabs are set up with their art, the collision box and their script for the certain bonus.
public GameObject SpeedH;
public GameObject SlowH;
public GameObject ThreeballsH;
public GameObject FireBallH;
public class YourClass : MonoBehaviour
{
void OnCollisionEnter(Collision Collider)
{
float buffChance = Random.Range(1, 10);
int buffChoice = Random.Range(1, 4);
if (buffChance < 3)
{
if (buffChoice == 1)
{
GameObject cubeSpawn = (GameObject)Instantiate(SpeedH, new Vector3(0,1,0), transform.rotation);
//cubeSpawn.AddComponent("Rigidbody");
//cubeSpawn.AddComponent("Bonus_PlayerSpeed");
}
else if (buffChoice == 2)
{
GameObject cubeSpawn= (GameObject)Instantiate(SlowH, transform.position, transform.rotation);
//cubeSpawn.AddComponent("Rigidbody");
//cubeSpawn.AddComponent("Bonus_SlowTime");
}
else if (buffChoice == 3)
{
GameObject cubeSpawn = (GameObject)Instantiate(ThreeballsH, transform.position, transform.rotation);
//cubeSpawn.AddComponent("Rigidbody");
//cubeSpawn.AddComponent("Bonus_3balls");
}
else if (buffChoice == 4)
{
GameObject cubeSpawn = (GameObject)Instantiate(FireBallH, transform.position, transform.rotation);
//cubeSpawn.AddComponent("Rigidbody");
//cubeSpawn.AddComponent("Bonus_FireBall");
}
}
}
}
[Edit by Berenger : removed Start and Update according to comments (they were empty), integrated the code inside a class (rename it if you want)]