Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BulletScript : MonoBehaviour
- {
- public float speed = 5f;
- void Start()
- {
- //ustawiamy po jakim czasie nas pocisk zniknie
- Destroy(gameObject,3);
- }
- // Update is called once per frame
- void Update()
- {
- //poruszamy pociskiem
- Move();
- }
- void Move()
- {
- //przesuwamy się w górę o naszą prędkość
- transform.position += Vector3.up * speed * Time.deltaTime;
- }
- private void OnTriggerEnter2D(Collider2D collision)
- {
- //Jeżeli dotkniemy element z tagiem Alien
- if (collision.gameObject.tag == "Alien")
- {
- //zniszczymy ten obiekt
- Destroy(collision.gameObject);
- //oraz siebie
- Destroy(gameObject);
- }
- }
- }
Add Comment
Please, Sign In to add comment