пуля.cs 727 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class пуля : MonoBehaviour
  5. {
  6. public float damage;
  7. public float speed;
  8. public hp hp;
  9. private void OnTriggerEnter2D(Collider2D collision)
  10. {
  11. if (collision.gameObject.tag=="Player" || collision.gameObject.tag=="Enemy")
  12. {
  13. hp = collision.GetComponent<hp>();
  14. hp.SetDamage(damage);
  15. Destroy(gameObject);
  16. }
  17. }
  18. void Start()
  19. {
  20. StartCoroutine(Delay());
  21. }
  22. IEnumerator Delay()
  23. {
  24. yield return new WaitForSeconds(1f);
  25. Destroy(gameObject);
  26. }
  27. void Update()
  28. {
  29. transform.Translate(speed,0,0);
  30. }
  31. }