Home > Back-end >  character does not attack when i click the mouse
character does not attack when i click the mouse

Time:12-13

i'm new in unity and programing so i don't know what's the problem at all https://youtu.be/e2PRI19Igbo I followed this video because i want to make combo attack but when I do the left click, character does not attackenter image description here i followe almost everything in video buy why my character does no attack?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCombat : MonoBehaviour
{
    public static PlayerCombat instance;
    public Animator animator;

    public Transform AttackPoint;
    public float AttackRange = 0.5f;
    public LayerMask enemyLayers;

    public int attackDamage = 40;
    public bool canReceiveInput;
    public bool inputReceived;

    private void Awake()
    {
        instance = this;
    }

    void Start()
    {
      
    }
    
    // Update is called once per frame
    void Update()
    {
        Attack();
    }
    public void Attack() 
    {
        if (Input.GetButtonDown("Fire1")) 
        {
           if (canReceiveInput) 
            {
                inputReceived = true;
                canReceiveInput = false;
            }
            else 
            {
                return;
            }
        }
    }

    public void InputManager()
    {
        if (!canReceiveInput) 
        {
            canReceiveInput = true;
        }
        else
        {
            canReceiveInput = false;
        }
    }
}

CodePudding user response:

following Anas Essouli answer, it also seems your problem come with your "canReceiveInput" variable. When you register a Fire1 input, you check if you have receive the input with your "canReceiveInput" bool var. But your variable is null at the beginning so it will never pass the condition. Your Input.GetButtonDown("Fire1") is enought to launch an attack animation. Just make sure that there is actual animation or projectile launched and not just code.

CodePudding user response:

in your script there is no animation trigger or attack functionality , you only check if input is Received by the click.

  • Related