Advertisement
kadyr

Untitled

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