using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour {
public Rigidbody2D RigidBall;
private AudioSource snd;
// Use this for initialization
void Start ()
{
Collider collider = GetComponent<Collider>();
RigidBall = GetComponent<Rigidbody2D>();
snd = GetComponent<AudioSource>();
Invoke("ballThrow", 3.0f);
}
public void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.name == "Player01" || coll.gameObject.name=="Player02")
{
snd.Play();
}
}
public void ResetBall()
{
RigidBall.angularVelocity = 0;
RigidBall.transform.position = new Vector3(0, 0, 0);
RigidBall.velocity = Vector3.zero;
RigidBall.isKinematic = false;
Invoke("ballThrow", 2.0f);
}
public void ballThrow()
{
float randomvar = Random.Range(0, 2);
if (randomvar <= 0.5)
{
RigidBall.AddForce(new Vector2(50, -10));
}
else
{
RigidBall.AddForce(new Vector2(-50, -10));
}
}
}