-
Notifications
You must be signed in to change notification settings - Fork 0
/
hit.cs
36 lines (31 loc) · 917 Bytes
/
hit.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class hit : MonoBehaviour
{
public GameObject bullet;
public PolygonCollider2D polygon;
public LayerMask layer;
private void Start()
{
polygon = transform.GetComponent<PolygonCollider2D>();
bullet = transform.GetComponent<GameObject>();
}
void Update()
{
if (isHit())
{
gameObject.SetActive(false);
FindObjectOfType<audiomanager>().Play("EnemyDeath");
for(int i = 0; i < 10; i++)
{
Score.scoreValue++;
}
}
}
public bool isHit()
{
RaycastHit2D raycast = Physics2D.BoxCast(polygon.bounds.center, polygon.bounds.size, 0f, Vector2.down, .1f, layer);
return raycast.collider != null;
}
}