using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeeleEnemy : MonoBehaviour
{
[Header("Attack Parameters")]
[SerializeField] private float attackCooldown;
[SerializeField] private float range;
[SerializeField] private int damage;
[Header("Collider Parameters")]
[SerializeField] private float colliderDistance;
[SerializeField] private BoxCollider2D boxCollider;
[Header("Player Layer")]
[SerializeField] private LayerMask playerLayer;
private float cooldownTimer = Mathf.Infinity;
private Animator anim;
private void Awake()
{
anim = GetComponent<Animator>();
}
private void Update()
{
cooldownTimer += Time.deltaTime;
if (PlayerInSight())
{
if (cooldownTimer >= attackCooldown)
{
cooldownTimer = 0;
anim.SetTrigger("Attack");
Debug.Log("Attack");
}
}
}
private bool PlayerInSight()
{
RaycastHit2D hit =
Physics2D.BoxCast(boxCollider.bounds.center + transform.right * range * transform.localScale.x * colliderDistance,
new Vector3(boxCollider.bounds.size.x * range, boxCollider.bounds.size.y, boxCollider.bounds.size.z),
0, Vector2.left, 0, playerLayer);
return hit.collider != null;
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawWireCube(boxCollider.bounds.center + transform.right * range * transform.localScale.x * colliderDistance,
new Vector3(boxCollider.bounds.size.x * range, boxCollider.bounds.size.y, boxCollider.bounds.size.z));
}
}
#Enemy not attacking
1 messages · Page 1 of 1 (latest)
yeah yea
oh hello
so whats the problem
try changing the value of cooldown timer
@stuck trout
what
@buoyant lynx do u even know what is the error
wha'ts Physics2D.BoxCast?
to create a box
unity doesnt have any doccumentation regarding it
which tutorial?
In this episode we'll finally create melee enemies and ranged enemies. Then we'll add a simple patrol behavior to our enemies.
➤ Knight Sprite Pack: https://assetstore.unity.com/packages/2d/characters/knight-sprite-sheet-free-93897
➤ Starting Project: https://github.com/nickbota/Unity-Platformer-Episode-9
➤ Complete Project: https://github.com...
try sswitching the vector 3 for vector2
no i cant do that cuz the z position is needed
do u know someone who can FIX it
stop pinging me
do u know how to fix it
no
anyone