Advertisement
kadyr

Untitled

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