0% found this document useful (0 votes)
2 views2 pages

Using UnityEngine; (2)

The ComboSystem script in Unity manages a combo attack system for a character. It allows players to execute a sequence of attacks within a specified time window, resetting if the time exceeds the limit. The script utilizes an Animator to trigger different attack animations based on the player's input.

Uploaded by

mohaidkhan49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Using UnityEngine; (2)

The ComboSystem script in Unity manages a combo attack system for a character. It allows players to execute a sequence of attacks within a specified time window, resetting if the time exceeds the limit. The script utilizes an Animator to trigger different attack animations based on the player's input.

Uploaded by

mohaidkhan49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using UnityEngine;

public class ComboSystem : MonoBehaviour


{
public float comboWindow = 0.5f; // ‫الوقت المسموح بين الضغطة والضغطة التالية‬
public string[] comboActions = { "Light Attack", "Heavy Attack", "Special
Attack" };
private float timeSinceLastPress = 0f;
private int currentComboStep = 0;
private bool isComboActive = false;
private Animator animator;

void Start()
{
animator = GetComponent<Animator>();
}

void Update()
{
timeSinceLastPress += Time.deltaTime;

if (Input.GetButtonDown("Fire1"))
{
ExecuteCombo();
}

if (timeSinceLastPress > comboWindow && isComboActive)


{
ResetCombo();
}
}

void ExecuteCombo()
{
if (timeSinceLastPress < comboWindow)
{
currentComboStep++;
}
else
{
currentComboStep = 1;
}

if (currentComboStep > comboActions.Length)


{
currentComboStep = 1;
}

PerformAttack(currentComboStep - 1);
timeSinceLastPress = 0f;
isComboActive = true;
}

void PerformAttack(int comboIndex)


{
string attackType = comboActions[comboIndex];
animator.SetTrigger(attackType);
}
void ResetCombo()
{
currentComboStep = 0;
isComboActive = false;
}
}

You might also like