Advertisement
kadyr

Untitled

Oct 3rd, 2021
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Bullet : MonoBehaviour
  4. {
  5. float speed = 10;
  6. Vector3 direction;
  7. private void Start()
  8. {
  9. GetComponent<AudioSource>().pitch = Random.Range(0.7f, 1f);
  10. }
  11. void Update()
  12. {
  13. transform.position += direction * speed * Time.deltaTime; //���������� ���� �� ����������� �� ������
  14. }
  15. public void setDirection(Vector3 dir)
  16. {
  17. direction = dir;
  18. }
  19.  
  20. private void OnTriggerEnter(Collider other)
  21. {
  22. if (other.tag == "Player")
  23. {
  24. FindObjectOfType<PlayerController>().ChangeHealth(-20); //������� ������ � ������ ��������
  25. }
  26. if (other.GetComponent<Enemy>()!=null)
  27. {
  28. other.GetComponent<Enemy>().ChangeHealth(-25);
  29. }
  30. Destroy(gameObject); //���� ����� ������������ ��� ������������ � ����� ������������
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement