Advertisement
Guest User

Bullet

a guest
Sep 23rd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Bullet : MonoBehaviour
  6. {
  7.     public float speedBullet;
  8.     public float damage;
  9.  
  10.     private void OnTriggerEnter2D(Collider2D collision)
  11.     {
  12.         if(collision.CompareTag("Player"))
  13.         {
  14.             Health health = collision.GetComponent<Health>();
  15.             health.TakeDamage(damage);
  16.             Destroy(gameObject);
  17.         }
  18.     }
  19.     private void Update()
  20.     {
  21.         transform.Translate(Vector3.right * speedBullet * Time.deltaTime);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement