Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

using UnityEngine;

public class PunchingSystem : MonoBehaviour

{

    public Collider punchCollider;

    public float punchCooldown = 1f;

    private float nextPunchTime = 0f;

    void Update()

    {

        if (Input.GetKeyDown(KeyCode.Space) && Time.time >= nextPunchTime)

        {

            // Trigger punch animation if you have one

            GetComponent<Animator>().SetTrigger("Punch");

            // Enable the punch collider

            punchCollider.enabled = true;

            // Set the cooldown for the next punch

            nextPunchTime = Time.time + punchCooldown;

        }

    }

    void OnTriggerEnter(Collider other)

    {

        // Check if the punching collider hits the target

        if (other.CompareTag("Target"))

        {

            Debug.Log("Target hit!");

            // Handle the target hit, such as reducing health or triggering a specific effect

        }

    }

    void OnTriggerExit(Collider other)

    {

        // Disable the punch collider after the punch

        punchCollider.enabled = false;

    }

}