Placido_GDD

DroneAtk

Nov 16th, 2021 (edited)
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class DroneAtk : MonoBehaviour
  6. {
  7.     public float droneDmg;
  8.     public float droneAtkInterval;
  9.     public Transform targetedObj;
  10.     public DroneManager droneManager;
  11.     public float atkRange;
  12.     float distFromTrgt;
  13.     public GameObject proj;
  14.     Rigidbody2D proj_Rb;
  15.     Projectile projScript;
  16.     public bool isFiring;
  17.     public float proj_Force;
  18.     Transform thisTransform;
  19.     public Transform d_Barrel;
  20.     // Start is called before the first frame update
  21.     void Start()
  22.     {  
  23.         thisTransform = this.gameObject.transform;
  24.         InvokeRepeating("FireProjectile",0.0f,droneAtkInterval);
  25.     }
  26.  
  27.    
  28.     void LateUpdate()
  29.     {
  30.         CheckIfFacingTarget();
  31.        
  32.     }
  33.     void CheckIfFacingTarget()
  34.     {
  35.         if(IsFacingObject() == true)
  36.         {
  37.             Debug.Log("facing target");
  38.         }
  39.        
  40.     }
  41.    
  42.     bool IsFacingObject()
  43.     {
  44.         Vector2 right  = transform.right;
  45.         Vector2 toOther = (targetedObj.position - thisTransform.position).normalized;
  46.         if(Vector2.Dot(right,toOther) < 0.7f)
  47.         {
  48.             Debug.Log("Not facing target");
  49.             return false;
  50.         }
  51.         return true;
  52.     }
  53.     void FireProjectile()
  54.     {
  55.         if(isFiring == true)
  56.         {
  57.             proj = Instantiate(proj,d_Barrel.position,d_Barrel.rotation);
  58.             proj_Rb = proj.GetComponent<Rigidbody2D>();
  59.             projScript = proj.GetComponent<Projectile>();
  60.             projScript.damage_Val = droneDmg;
  61.             proj_Rb.AddForce(transform.right * proj_Force);
  62.         }
  63.     }
  64.    
  65. }
  66.  
Add Comment
Please, Sign In to add comment