I’m fairly new in unity and game development as a whole but pretty experienced with programming as I’ve been coding for almost two years in C++ and started learning C# maybe a month ago(Which was fairly easy) to get into unity. My question is, I’m trying to achieve realistic bounciness when a ball(sprite) hits a paddle(sprite) in which every time a collision occurs the ball loses bounciness(I decrease the bounciness by 0.2) however it doesn’t seem to work. Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RealisticBounce : MonoBehaviour
{
[SerializeField] private PhysicsMaterial2D physicsMaterial2D;
private void OnCollisionEnter2D()
{
if (physicsMaterial2D.bounciness >= 0)
physicsMaterial2D.bounciness -= 0.2f;
}
}