CakeMeister

Bullet phan 12

Jul 6th, 2017
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Bullet : MonoBehaviour {
  6.  
  7.    
  8.     public float lifetime = 2;
  9.    
  10.  
  11.     void Start () {
  12.        
  13.     }
  14.  
  15.  
  16.     private void OnTriggerEnter2D(Collider2D col)
  17.     {
  18.         if (col.isTrigger == false )
  19.         {
  20.             if (col.CompareTag("Player"))
  21.             {
  22.                 col.SendMessageUpwards("Damage", 1);
  23.             }
  24.             Destroy(gameObject);
  25.         }
  26.    
  27.     }
  28.  
  29.     // Update is called once per frame
  30.     void Update () {
  31.         lifetime -= Time.deltaTime;
  32.         if (lifetime <= 0)
  33.             Destroy(gameObject);
  34.     }
  35. }
Add Comment
Please, Sign In to add comment