I get no errors, but nothing happens when I press space.
Any more info needed can be provided.
Thanks.
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attack : MonoBehaviour
{
public float attackRange = 5f;
public float attackDamage = 1f;
int layerMask = 1 << 9;
void FixedUpdate()
{
AttackRaycast();
}
private void AttackRaycast()
{
//left
if (gameObject.GetComponent().playerFacingX == -1 && Input.GetKeyDown(KeyCode.Space))
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.TransformDirection(Vector2.left), attackRange, layerMask);
if (hit)
{
Debug.Log(“HIT”);
}
}
//right
else if (gameObject.GetComponent().playerFacingX == 1 && Input.GetKeyDown(KeyCode.Space))
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.TransformDirection(Vector2.right), attackRange, layerMask);
if (hit)
{
Debug.Log(“HIT”);
}
}
//down
else if (gameObject.GetComponent().playerFacingY == -1 && Input.GetKeyDown(KeyCode.Space))
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.TransformDirection(Vector2.down), attackRange, layerMask);
if (hit)
{
Debug.Log(“HIT”);
}
}
//up
else if (gameObject.GetComponent().playerFacingY == 1 && Input.GetKeyDown(KeyCode.Space))
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.TransformDirection(Vector2.up), attackRange, layerMask);
if (hit)
{
Debug.Log(“HIT”);
}
}
}
}