-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoseCollider.cs
68 lines (60 loc) · 1.8 KB
/
LoseCollider.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
60
61
62
63
64
65
66
67
68
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoseCollider : MonoBehaviour {
public static LoseCollider instance;
[SerializeField] GameObject loseParticles;
[HideInInspector] public int ballTouches;
Vector2 collisionPoint;
GameObject shootRenderer;
ShootSpotRenderer srr;
Vector2 sr;
bool dead;
void Start () {
if (instance == null){
instance = this;
}else if (instance !=this){
Destroy(gameObject);
}
shootRenderer = GameObject.FindGameObjectWithTag("ShootSpot");
srr = shootRenderer.GetComponent<ShootSpotRenderer>();
}
void OnCollisionEnter2D (Collision2D collider){
if (collider.gameObject.tag == "Ball") {
if (ballTouches < 1){
ContactPoint2D contact = collider.contacts[0];
collisionPoint = contact.point;
sr.x = collisionPoint.x;
srr.newPos.x = collisionPoint.x;
shootRenderer.SetActive(true);
ballTouches++;
}
}else if (collider.gameObject.tag == "Breakable" && !dead){
dead = true;
BallShooter.instance.dead = true;
var losePos = collider.transform.position.x;
loseParticles.SetActive(true);
var newPos = new Vector2(losePos, 1f);
loseParticles.transform.position = newPos;
Invoke("CallDeath",3f);
}else if (collider.gameObject.tag == "UnbreakableBricks"){
Destroy(collider.gameObject);
}
}
public void SetPositionForShoot(){
if (BallShooter.instance == null){
Debug.LogWarning ("BallShooter Script is not assinged");
return;
}else if (BallShooter.instance != null){
BallShooter.instance.basePos.x = collisionPoint.x;
}
}
void CallDeath(){
GameManager.instance.Death();
BallShooter.instance.DeadOrNot();
dead = false;
}
public void ParticleReset(){
loseParticles.SetActive(false);
}
}