I am new to programming in unity and after searching for stuff online i thought this was going to work, but it doesn’t.
Here’s the code:
using UnityEngine;
public class weaponAttack : MonoBehaviour
{
[SerializeField]
private float secondAttackDelay = 10f;
private float secondAttackTimer = 0f;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
secondAttackTimer += 1;
if (secondAttackTimer >= secondAttackDelay)
{
Debug.Log("Stab!");
secondAttackTimer = 0;
}
if (Input.GetMouseButtonUp(0) && secondAttackTimer < secondAttackDelay)
{
Debug.Log("Slash!");
}
}
}
}
What i want is so that when you click the console displays “Slash!”, but when you hold down the mouse button for long enough(secondAttackDelay) the console would show “Stab!” instead. It always displays “Stab!” no matter how quick i am to click.
What is the problem here?
Can i use a coroutine to do the timing? (I tried it)