Advertisement
johnnygoodguy2000

BulletController.cs

Apr 28th, 2024 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5.  
  6. public class BulletController : MonoBehaviour
  7. {
  8.     public PlayerController player;
  9.  
  10.     public float bulletSpeed;
  11.  
  12.     public GameObject enemyDeathPartical;
  13.  
  14.     public GameObject bulletImpactPartical;
  15.  
  16.     public int pointsForKillingEnemy;
  17.  
  18.     public float rotationSpeed;
  19.  
  20.     public int bulletDamage;
  21.  
  22.     //private Rigidbody2D myRigidBody2D;//
  23.  
  24.    
  25.  
  26.  
  27.     // Start is called before the first frame update
  28.     void Start()
  29.     {
  30.         player = FindAnyObjectByType<PlayerController>();
  31.         if (player.transform.localScale.x < 0)
  32.         {
  33.             bulletSpeed = -bulletSpeed;
  34.             rotationSpeed = -rotationSpeed;
  35.  
  36.    
  37.         }
  38.     }
  39.  
  40.     // Update is called once per frame
  41.     void Update()
  42.     {
  43.         GetComponent<Rigidbody2D>().velocity = new Vector2(bulletSpeed, GetComponent<Rigidbody2D>().velocity.y);
  44.  
  45.         GetComponent<Rigidbody2D>().angularVelocity = rotationSpeed; // Make the bullet rotate if needed
  46.  
  47.        
  48.  
  49.  
  50.     }
  51.  
  52.     void OnTriggerEnter2D(Collider2D other)
  53.     {
  54.  
  55.         if (other.tag == "Enemy")
  56.         {
  57.             //Instantiate(enemyDeathPartical, other.transform.position, other.transform.rotation);
  58.             //Destroy(other.gameObject);
  59.            // ScoreManager.AddPoints(pointsForKillingEnemy);
  60.            other.GetComponent<EnemyHealthManager>().giveDamage(1);
  61.  
  62.         }
  63.  
  64.         if (other.tag == "Boss")
  65.         {
  66.             //Instantiate(enemyDeathPartical, other.transform.position, other.transform.rotation);
  67.             //Destroy(other.gameObject);
  68.            // ScoreManager.AddPoints(pointsForKillingEnemy);
  69.             other.GetComponent<BossHealthManager>().giveDamage(1);
  70.         }
  71.  
  72.        
  73.  
  74.         Instantiate(bulletImpactPartical, transform.position, transform.rotation);
  75.         Destroy (gameObject);
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement