Pro_Unit

Ammo

Mar 7th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Ammo : MonoBehaviour
  6. {
  7.     public float speed;
  8.     public float destroyTime;
  9.  
  10.     public int damage = 2;
  11.  
  12.     void Start()
  13.     {
  14.         Invoke("DestroyAmmo", destroyTime);
  15.     }
  16.  
  17.     void Update()
  18.     {
  19.         transform.Translate(Vector2.left * speed * Time.deltaTime);
  20.     }
  21.  
  22.     private void OnTriggerEnter2D(Collider2D collision)
  23.     {
  24.         HpEnemy enemy = collision.GetComponent<HpEnemy>();
  25.  
  26.         if (enemy != null);
  27.         {
  28.             enemy.TakeDamage(damage);
  29.         }
  30.         Destroy(gameObject);
  31.     }
  32. }
Add Comment
Please, Sign In to add comment