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 | //ustawiamy po jakim czasie nas pocisk zniknie | |
11 | Destroy(gameObject,3); | |
12 | } | |
13 | ||
14 | // Update is called once per frame | |
15 | void Update() | |
16 | { | |
17 | //poruszamy pociskiem | |
18 | Move(); | |
19 | } | |
20 | ||
21 | void Move() | |
22 | { | |
23 | //przesuwamy się w górę o naszą prędkość | |
24 | transform.position += Vector3.up * speed * Time.deltaTime; | |
25 | } | |
26 | ||
27 | private void OnTriggerEnter2D(Collider2D collision) | |
28 | { | |
29 | //Jeżeli dotkniemy element z tagiem Alien | |
30 | if (collision.gameObject.tag == "Alien") | |
31 | { | |
32 | //zniszczymy ten obiekt | |
33 | Destroy(collision.gameObject); | |
34 | //oraz siebie | |
35 | Destroy(gameObject); | |
36 | } | |
37 | } | |
38 | } | |
39 |