using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour {
public int speed = 15;
Rigidbody2D ball;
public float change = 100.0f;
// Use this for initialization
void Start () {
ball = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate () {
ball.velocity = new Vector3(speed,0,0);
}
void OnCollisionEnter2D (Collision2D other) {
speed = -speed;
ball.velocity = new Vector2(ball.velocity.x,Random.Range(-change, change));
}
}
As you can see, in OnCollisionEnter2D I’m trying to set a random Y velocity, but it does nothing. What’s wrong?