Question by
Hlodvic · Dec 24, 2021 at 05:59 PM ·
bounciness
How to control bouncing with a controller ?
Hello, I am making a 2D game, there is a ball, I would like to activate and desactivate the "bounciness" with the space bar, and I don't understand how to do it. I've been trying for hours and I can't do it (I'm a beginner), please help me float bounce; GameObject ballon; Rigidbody2D rig;
void Start()
{
ballon = GameObject.FindGameObjectWithTag("ball");
bounce = rig.sharedMaterial.bounciness;
gameObject.AddComponent<Rigidbody2D>();
rig.sharedMaterial.bounciness = ballon.gameObject.GetComponents<Rigidbody2D>().Length;
}
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
bounce--;
}
seriously idk what I'm doing, I think I don't understand the logic of c# for now :(
Comment