-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.cs
48 lines (39 loc) · 1.19 KB
/
Bullet.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
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
public Animator animator;
public float speed = 20f;
public Rigidbody2D rb;
public float damage;
// Start is called before the first frame update
void Start()
{
//animator.SetBool("OnHit",false);
rb.velocity = transform.right * speed;
}
//When the bullet hits something
private void OnTriggerEnter2D(Collider2D other) {
speed = 0f;
rb.velocity = transform.right * speed;
//animator.SetBool("OnHit",true);
//StartCoroutine("wait");
Destroy(gameObject);
//If the bullet hits another player, the player loses health
if(other.gameObject.tag == "Player")
{
other.gameObject.GetComponent<playerManager>().setHealth(damage);
}
else if(other.gameObject.tag == "Explosive")
{
other.gameObject.GetComponent<TNTscript>().setHealth(damage);
}
}
//Waits for the animation to finish
IEnumerator wait()
{
yield return new WaitForSeconds(5);
}
}