I have this code for player combat. I have it set to attack and play an animation then detect enemy colliders in the box. I have two separate hitEnemies for when chrouching and not. I can’t find a way to get my character to crouch and attack and get the debug.log to activate.
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player_combat : MonoBehaviour
{
public Animator animator;
public Transform attackPoint;
public Vector2 swordSize;
public int swordCollider = 5;
public int swordCollider2 = 5;
public LayerMask enemyLayers;
public Transform attackPoint2;
public Vector2 swordSize2;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.N))
{
Attack();
}
}
void Attack()
{
//Play animation
animator.SetTrigger("Attack");
//Detect enemies in range of box
Collider2D[] hitEnemies = Physics2D.OverlapBoxAll(attackPoint.position, swordSize, swordCollider, enemyLayers);
Collider2D[] hitEnemies2 = Physics2D.OverlapBoxAll(attackPoint2.position, swordSize2, swordCollider, enemyLayers);
//Damage them
foreach (Collider2D enemy in hitEnemies)
{
Debug.Log("We hit" + enemy.name);
}
foreach (Collider2D enemy in hitEnemies2)
if (Input.GetButtonDown("Crouch"))
{
Debug.Log("We hit" + enemy.name);
}
}
private void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireCube(attackPoint.position, swordSize);
if (attackPoint2 == null)
return;
Gizmos.DrawWireCube(attackPoint2.position, swordSize2);
}
}
I have this code for player combat. I have it set to attack and play an animation then detect enemy colliders in the box. I have two separate hitEnemies for when chrouching and not. I can’t find a way to get my character to crouch and attack and get the debug.log to activate.