Skip to content

Instantly share code, notes, and snippets.

@ELGReeND
Created July 3, 2018 19:21
Show Gist options
  • Save ELGReeND/2934697a722d44931158ca755514051e to your computer and use it in GitHub Desktop.
Save ELGReeND/2934697a722d44931158ca755514051e to your computer and use it in GitHub Desktop.
Time.realtimeSinceStartup
void Update()
{
if (Input.GetMouseButtonDown(moveBtn)) { //клик или зажатие
t_ = Time.realtimeSinceStartup; //запоминаем время нажатия
status = 0; //скрытый но активный
}
if (Input.GetMouseButton(moveBtn)) { //кнопка была зажата в этом кадре
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
int layerMask = 1 << 0; //только слой дефолт
if (!Physics.Raycast(ray, out hit, 200f, layerMask))
{
return;
}
transform.position = hit.point + hit.normal * surfaceOffset;
if (Vector3.Distance(setTargetOn.transform.position, transform.position) >= 0.2)
{
status = 0; //скрытый но активный
}
else { status = 1; }
/*if (setTargetOn != null)
{
setTargetOn.SendMessage("SetTarget", transform);
}*/
}
if (Input.GetMouseButtonUp(moveBtn))
{
if ((Time.realtimeSinceStartup - t_) >= 0.15f) //если прошло слишком много времени значит БЫЛО зажатие
{
status = 1; //выключаем
}
else { status = 2; } //иначе это был клик, включаем отображение
}
if (status == 0 || status == 1)
{
image.SetActive(false);
}
else { image.SetActive(true); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment