giganciprogramowania

BulletScript l16

Jun 16th, 2023
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         if (collision.gameObject.tag == "Alien" || collision.gameObject.tag == "AlienBullet")
  30.         {
  31.             Destroy(collision.gameObject);
  32.             Destroy(gameObject);
  33.         }
  34.     }
  35. }
  36.  
Add Comment
Please, Sign In to add comment