Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class DroneAtk : MonoBehaviour
- {
- public float droneDmg;
- public float droneAtkInterval;
- public Transform targetedObj;
- public DroneManager droneManager;
- public float atkRange;
- float distFromTrgt;
- public GameObject proj;
- Rigidbody2D proj_Rb;
- Projectile projScript;
- public bool isFiring;
- public float proj_Force;
- Transform thisTransform;
- public Transform d_Barrel;
- // Start is called before the first frame update
- void Start()
- {
- thisTransform = this.gameObject.transform;
- InvokeRepeating("FireProjectile",0.0f,droneAtkInterval);
- }
- void LateUpdate()
- {
- CheckIfFacingTarget();
- }
- void CheckIfFacingTarget()
- {
- if(IsFacingObject() == true)
- {
- Debug.Log("facing target");
- }
- }
- bool IsFacingObject()
- {
- Vector2 right = transform.right;
- Vector2 toOther = (targetedObj.position - thisTransform.position).normalized;
- if(Vector2.Dot(right,toOther) < 0.7f)
- {
- Debug.Log("Not facing target");
- return false;
- }
- return true;
- }
- void FireProjectile()
- {
- if(isFiring == true)
- {
- proj = Instantiate(proj,d_Barrel.position,d_Barrel.rotation);
- proj_Rb = proj.GetComponent<Rigidbody2D>();
- projScript = proj.GetComponent<Projectile>();
- projScript.damage_Val = droneDmg;
- proj_Rb.AddForce(transform.right * proj_Force);
- }
- }
- }
Add Comment
Please, Sign In to add comment