Skip to content

Instantly share code, notes, and snippets.

@xjjon
Created November 29, 2023 02:13
Show Gist options
  • Save xjjon/032a5576fd9cc98002d52c66222cc136 to your computer and use it in GitHub Desktop.
Save xjjon/032a5576fd9cc98002d52c66222cc136 to your computer and use it in GitHub Desktop.
public class Firepoint : MonoBehaviour
{
public float rayCastDistance = 10f;
public LayerMask layerMask; // Assign the desired layer(s) in the Unity Inspector.
private EnemyHealth enemyHealth;
float damageOvertime = 5f;
SpeedBuff speedBuffScriptableObject;
private void Start()
{
enemyHealth = FindObjectOfType<EnemyHealth>();
}
private void OnDrawGizmos()
{
// Draw a line to represent the raycast direction and distance in the scene view.
Gizmos.color = Color.red; // You can choose any color you like
Vector2 rayDirection = new Vector2(Mathf.Cos(transform.eulerAngles.z * Mathf.Deg2Rad), Mathf.Sin(transform.eulerAngles.z * Mathf.Deg2Rad));
Gizmos.DrawRay(transform.position, rayDirection * rayCastDistance);
}
private void Update()
{
float angle = transform.eulerAngles.z;
Vector2 rayDirection = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad)); // DYNAMIC ROTATION 2d SPACE
RaycastHit2D raycastHit2D = Physics2D.Raycast(transform.position, rayDirection, rayCastDistance, layerMask); //specific mask
if (raycastHit2D.collider != null)
{
/*Debug.Log(“Hit ” + raycastHit2D.collider.gameObject.name);
BuffableEntity buffableEntity = raycastHit2D.collider.gameObject.GetComponent<BuffableEntity>();
if (buffableEntity != null)
{
var timedBuff = speedBuffScriptableObject.InitializeBuff(raycastHit2D.collider.gameObject);
buffableEntity.AddBuff(timedBuff);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment