Advertisement
kadyr

Untitled

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