View difference between Paste ID: xUZ4SL0e and PdMkmzS6
SHOW: | | - or go back to the newest paste.
1
using System.Collections;
2
using System.Collections.Generic;
3
using UnityEngine;
4
 
5
public class BulletScript : MonoBehaviour
6
{
7
    public float speed = 5f;
8
    void Start()
9
    {
10
        //delete the bullet after 3 seconds
11
        Destroy(gameObject,3);
12
    }
13
 
14
    // Update is called once per frame
15
    void Update()
16
    {
17
        //bullet movement
18
        Move();
19
    }
20
 
21
    void Move()
22
    {
23
        //moving up with the specified speed
24
        transform.position += Vector3.up * speed * Time.deltaTime;
25
    }
26
 
27
    private void OnTriggerEnter2D(Collider2D collision)
28
    {
29
        //If we touch an element with Alien tag
30
        if (collision.gameObject.tag == "Alien")
31
        {
32
            //Destroy that object
33
            Destroy(collision.gameObject);
34
            //and yourself
35
            Destroy(gameObject);
36
        }
37
    }
38
}