how to make an autoclicker in unity code example
Example: how to make an auto clicker UNITY
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public class AutoClicker : MonoBehaviour
{
public bool Going = false;
public bool Waiting = false;
const int MOUSEEVENTF_LEFTDOWN = 2;
const int MOUSEEVENTF_LEFTUP = 4;
const int INPUT_MOUSE = 0;
[DllImport("User32.dll", SetLastError = true)]
public static extern int SendInput(int nInputs, ref INPUT pInputs, int cbSize);
void Update()
{
if (Input.GetKey(KeyCode.Tab)) {
Going = !Going;
}
if (Going == true && Waiting == false) {
Waiting = true;
timer1_Tick();
}
}
public struct MOUSEINPUT
{
public int dx;
public int dy;
public int mouseData;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
public struct INPUT
{
public uint type;
public MOUSEINPUT mi;
};
private void timer1_Tick()
{
INPUT i = new INPUT();
i.type = INPUT_MOUSE;
i.mi.dx = 0;
i.mi.dy = 0;
i.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
i.mi.dwExtraInfo = IntPtr.Zero;
i.mi.mouseData = 0;
i.mi.time = 0;
SendInput(1, ref i, Marshal.SizeOf(i));
i.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, ref i, Marshal.SizeOf(i));
Waiting = false;
}
}