@Maganta Hi, Maganta thnak you so much for you answer, I really appreciate it, but Im not sure if I used this infos right. Also I couldnt fit this in the comment section. My code is a total mess and Im kinda confused, especially because I dont get any errors, eventhough its not working. This ofc is because of me being unexpirienced and I have to admit I have no idea what I should do. Heres the code:
public class Move : MonoBehaviour
{
public int damage;
private float timeBtwAttack;
public float startTimeBtwAttack;
public float attackRange;
public Vector2 moveInputValue;
public Vector2 attackDir = Vector2.right; // independent direction of attack
public float attackCooldown;
float _lastAttackTime;
public Transform Player;
public Transform attackPos;
public LayerMask whatIsEnemies;
public float attackRangeX;
public float attackRangeY;
public float ValueIsGiven;
//Move Start
[SerializeField] private Rigidbody2D rb2D;
[SerializeField] private float speed;
private void OnMove(InputValue value)
{
var attackPos = (Vector2)transform.position + attackDir*attackRange; //Get the world coordinates of attackPos
moveInputValue = value.Get<Vector2>();
if(moveInputValue != Vector2.zero){
attackDir = moveInputValue.normalized; //When the player stops moving, use the last movement direction as the attack direction
}
if(ValueIsGiven >= 1){
Debug.Log(moveInputValue);
}
}
public float Angle(Vector2 vector2)
{
return 360 - (Mathf.Atan2(vector2.x, vector2.y) * Mathf.Rad2Deg * Mathf.Sign(vector2.x));
}
private void MoveLogicMethod()
{
// Vector2 result = moveInputValue * speed * Time.fixedDeltaTime;
Vector2 result = moveInputValue.normalized * speed; //fixedDeltaTime is not needed here
rb2D.velocity = result;
}
private void FixedUpdate()
{
MoveLogicMethod();
}
//Move End
//Attack Start
public void OnPlayerAttacking()
{
// If attacking too close to previous attack, ignore this input.
if (Time.time - _lastAttackTime < attackCooldown) return;
var enemiesToDamage = Physics2D.OverlapBoxAll(
attackPos.position,
new Vector2(attackRangeX, attackRangeY),
0,
whatIsEnemies
);
foreach (var enemy in enemiesToDamage) {
enemy.GetComponent<Enemy>().TakeDamage(damage);
}
_lastAttackTime = Time.time;
}
void OnDrawGizmosSelected(){
Gizmos.color = Color.black;
Gizmos.DrawWireCube(attackPos.position, new Vector2(attackRangeX, attackRangeY));
}
//Attack End
}
I also havent used any if statements yet, since I think it would even further confuse me. Im kind of ashamed asking you for help again, especially after you gave me such a long and good answer.