Player trigger on platform with prefab
So I want the player to bounce up when he hits the platform. My current code works, but only lets 1 platform have this. I want it so that every platform I make from the prefab does this. Currently I have attached a game object to the platform but is there another way to make it without assigning a game object? This is my code:
public GameObject player;
private Rigidbody2D rb1;
private void OnTriggerEnter2D(Collider2D other)
{
rb1 = player.GetComponent<Rigidbody2D>();
rb1.velocity = Vector2.zero;
rb1.AddForce(Vector2.up * bounceFactor, ForceMode2D.Impulse);
}
Comment