Hello unity newbie here. I have a problem with one of my scripts. I´m trying to make a simple pong game where the ball will go faster everytime it hits one of the players.
But the ball only goes slower! Here is my script:
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour {
public int ballSpeed;
void Start () {
rigidbody.AddForce(new Vector3(Random.Range(-100.0F, 100.0F), 0, 0) * ballSpeed * Time.deltaTime);
}
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "Player01")
{
float X = Random.Range(-5.0F, -15.0F);
float Y = Random.Range(6.0F, -6.0F);
ballSpeed += 100;
rigidbody.AddForce(new Vector3(X, Y, 0) * ballSpeed * Time.deltaTime);
}
else if(col.gameObject.name == "Player02")
{
float X = Random.Range(5.0F, 15.0F);
float Y = Random.Range(6.0F, -6.0F);
ballSpeed += 100;
rigidbody.AddForce(new Vector3(X, Y, 0) * ballSpeed * Time.deltaTime);
}
}
}