Vladkiber

Влад

Apr 6th, 2020
86
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 Ammo : MonoBehaviour
  6. {
  7.     public float speed;
  8.     public float destroyTime;
  9.     public int damage = 3;
  10.  
  11.     void Start()
  12.     {
  13.         Invoke("DestroyAmmo", destroyTime);    
  14.     }
  15.  
  16.     void Update()
  17.     {
  18.         transform.Translate(Vector2.left * speed * Time.deltaTime);
  19.     }
  20.  
  21.     private void OnTriggerEnter2D(Collider2D collision)
  22.     {
  23.         HpEnemy enemy = collision.GetComponent<HpEnemy>();
  24.  
  25.         if (enemy != null)
  26.         {
  27.             enemy.TakeDamage(damage);
  28.         }
  29.  
  30.         Destroy(gameObject);
  31.        
  32.     }
  33. }
Add Comment
Please, Sign In to add comment