-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBall.cs
60 lines (48 loc) · 1.33 KB
/
Ball.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour {
private Vector3 direction;
private Vector3 vect;
// Use this for initialization
void Start () {
Init ();
}
void Init(){
float Dirx = Random.Range(10.0f , 15.0f);
float Dirz = Random.Range(0,2);
if (Dirz == 0){
vect = new Vector3( Dirx, 0, 10.0f);
}
else {
vect = new Vector3( Dirx, 0, -10.0f);
}
rigidbody.velocity = vect * 20;
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.CompareTag("TopWall")){
GameLogic.Instance.player1score +=1;
GameLogic.Instance.instantiateBall();
Destroy(gameObject);
}
else if (collision.gameObject.CompareTag("BottomWall")){
GameLogic.Instance.player2score +=1;
GameLogic.Instance.instantiateBall();
Destroy(gameObject);
}
else if (Mathf.Abs(rigidbody.velocity.magnitude) < 1500){
if (collision.gameObject.CompareTag("RedPad") || collision.gameObject.CompareTag("GreenPad")){
if (collision.gameObject.CompareTag("RedPad")){
rigidbody.AddForce(new Vector3 (0.0f,0.0f,-1.0f) , ForceMode.Impulse) ;
}
else
rigidbody.AddForce(new Vector3 (0.0f,0.0f,1.0f) , ForceMode.Impulse) ;
}
else {
rigidbody.velocity = rigidbody.velocity * 1.10f;
}
}
}
// Update is called once per frame
void Update () {
}
}