Script attached to prefab stops working after multiple executes

Hello, good day. At the moment i’m trying to make a simple platform game. I managed to get the mechanics working, most of it at least. I have 2 prefabs, one for normal platform and one for mega bouncy platform, they are using the same code and both of those prefabs stops working after playing for awhile. Player movement is constrained to x axis only, platforms just gives the player vertical velocity (i might phrased it all wrong tho, i’m super noob in Unity, started couple of days ago).

So, here is a code for both platforms.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Bounce : MonoBehaviour
{
   
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.GetComponent().velocity.y <= 0)
        {
            collision.gameObject.GetComponent().AddForce(Vector3.up * 400f);
        }
       
    }
   
}
`
 
 `
`

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BigBounce : MonoBehaviour
{

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.GetComponent<Rigidbody2D>().velocity.y <= 0)
    {
        collision.gameObject.GetComponent<Rigidbody2D>().AddForce(Vector3.up * 800f);
    }

}

}

Here is a code for player controller.

</pre></code>


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class Controller : MonoBehaviour
{

private Rigidbody2D rb2d;
private float moveInput;
private float speed = 5f;
public TextMeshProUGUI scoreText;
private float topScore= 0.0f;
// Start is called before the first frame update
void Start()
{
    rb2d = GetComponent<Rigidbody2D>();
}

void Update()
{
if(rb2d.velocity.y > 0 && transform.position.y > topScore)
{
topScore = transform.position.y;
}

    scoreText.text = "Height " + Mathf.Round(topScore).ToString();
}
// Update is called once per frame
void FixedUpdate()
{
    moveInput = SimpleInput.GetAxis("Horizontal");
    rb2d.velocity = new Vector2(moveInput * speed, rb2d.velocity.y);
}

}

And here is a code for “destroyer”. It has a box collider and when it collides with a platform that is off camera it determines if it should spawn normal platform or big bounce platform. Then it moves or deletes and spawns a platform according to the probability.

</pre></code></code>


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Destroy : MonoBehaviour
{

public Text text;
public GameObject player;
public GameObject platformPreFab;
public GameObject springPreFab;
private GameObject myPlat;
// Start is called before the first frame update
void Start()
{
   
}

// Update is called once per frame
void Update()
{
   
}

private void OnTriggerEnter2D(Collider2D collision)
{
    if (collision.gameObject.name.StartsWith("Platform"))
    {
        if (Random.Range(1, 9) == 1)
        {
            Destroy(collision.gameObject);
            Instantiate(springPreFab, new Vector2(Random.Range(-2.2f, 2.2f), player.transform.position.y + (12 + Random.Range(0.1f, 0.3f))), Quaternion.identity);
        }
        else
        {
            collision.gameObject.transform.position = new Vector2(Random.Range(-2.2f, 2.2f), player.transform.position.y + (12 + Random.Range(0.1f, 0.3f)));
        }
    }
    else if (collision.gameObject.name.StartsWith("Spring"))
    {
        if (Random.Range(1, 9) == 1)
        {
            collision.gameObject.transform.position = new Vector2(Random.Range(-2.2f, 2.2f), player.transform.position.y + (12 + Random.Range(0.1f, 0.3f)));
           
        }
        else
        {
            Destroy(collision.gameObject);
            Instantiate(platformPreFab, new Vector2(Random.Range(-2.2f, 2.2f), player.transform.position.y + (12 + Random.Range(0.1f, 0.3f))), Quaternion.identity);
        }
    }
}

}

After some time playing some platforms simply don’t “bounce” the player up. The player falls onto them and nothing happens. Collisions work so i’m not falling through them and i can move left and right freely, but the vertical velocity is not applied. rg2d and colliders are applied correctly cause they work normally, i think. Please, can someone point me in the right direction as to why it’s hapenning? And please remember that i am really, REALLY new to C#.
`

So the only thing I can think off is the player having greater downward velocity than the force you use to push it up again. You can try resetting the player velocity before applying the bounce on it. However for a bouncy platform I would just use a physics material. I hope this helps!