Advertisement
kadyr

bullet

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