-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulletcode.cs
40 lines (37 loc) · 997 Bytes
/
bulletcode.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//This class contains the script for the bullet game object.
public class bulletcode : MonoBehaviour
{
public int number;
private int counter = 0;
//This function destroys the bullet after a certain amount of time.
void FixedUpdate()
{
if (counter == number)
{
Destroy(gameObject);
}
else
{
counter += 1;
}
}
//This function destroys the bullet when the bullet collides with anything object other than a type of bullet object.
void OnCollisionEnter2D(Collision2D collision)
{
string tagg = collision.gameObject.tag;
if (tagg == "bullet")
{
return;
}else if(tagg == "bullet2")
{
return;
}else if(tagg == "bullet3")
{
return;
}
Destroy(gameObject);
}
}