Advertisement
kadyr

Untitled

Oct 31st, 2021
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. public class Bullet : MonoBehaviour
  5. {
  6.     private Vector3 direction;
  7.  
  8.     [SerializeField]
  9.     private float speed;
  10.  
  11.     public void SetDirection(Vector3 dir)
  12.     {
  13.         direction = dir;
  14.     }
  15.  
  16.     void Start() { }
  17.  
  18.     void Update()
  19.     {
  20.         transform.position += direction * Time.deltaTime * speed;
  21.     }
  22.  
  23.     private void OnTriggerEnter(Collider other)
  24.     {
  25.         if (other.tag == "Player")
  26.         {
  27.             other.gameObject.GetComponent<PlayerController>().ChangeHealth(-20);
  28.             Destroy(this.gameObject);
  29.         }
  30.  
  31.         if (other.gameObject.tag == "Enemy")
  32.         {
  33.             Destroy(other.gameObject);
  34.             Destroy(this.gameObject);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement