Change value on mouse drag

Hi everybody !

First i’m french guy and my english is not perfect, sorry for mistakes :stuck_out_tongue:

I’m a begginer on Unity and i try to understand how programming. Currently, i try to make a Clicker Game for fun
but i have a problem : For my Clicker Game i don’t want add value on mouse click but when you drag the mouse on a sprite. Now my script is like that :

using UnityEngine;
using System.Collections;

public class Click : MonoBehaviour
{
public UnityEngine.UI.Text GpC;
public UnityEngine.UI.Text GoldDisplay;
public float Gold = 0.00f;
public int GoldPerClick = 1;
public var drag: float;

void Update ()
{
GoldDisplay.text = “Gold : " + Gold.ToString(“F0”);
GpC.text = GoldPerClick + " Gold / Click”;
}

public void MouseDrag ()
{
Gold += GoldPerClick ;
}
}

I have others scripts for buy Gold per Sec and Gold buy Click but i think it’s not necessary for my problem

After i add on a sprite a component event trigger/drag/ and i add my script.
It’s work (yes ! :smile:) but problem is my gold per sec is 1 but when i drag on my sprite, Unity add with the speed of the mouse so you add 50-100 gold each sec.

I want (in begin of game) add 1 gold each sec whatever your move speed with mouse

I try to understand how WaitForSecond and StartCoroutines works but i don’t understand, or maybe another option more simpliest probably exist

Thanks you in advance everybody :slight_smile:

First get time mouse started dragging.
Check how long passed since user started dragging. Also check mouse distance passed (user might’ve just clicked and didn’t move mouse - that’s drag too). Add gold depending on that.

Sorry but i’m very begginer, where is time mouse for you ?

What he means is:
When the mouse starts dragging, record the time (you get it from Time.time) that happened. You can compare against that stored value later, and see how many seconds it has been since he started clicking.