private void Interact(RaycastHit2D hit) { PrologueObject obj = hit.transform.GetComponent <PrologueObject>(); obj.ActiveObject(gameObject); StartCoroutine(DeactiveObject_WithDelay(obj)); }
void DetectTouch() { if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject()) { if (Input.GetMouseButtonDown(0)) { touchedPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(touchedPos, Vector2.zero, 0, LayerMask.GetMask("SmallStructure")); if (hit && (hit.transform.CompareTag("NPC") || hit.transform.CompareTag("InteractiveObject"))) { PrologueObject obj = hit.transform.GetComponent <PrologueObject>(); obj.ActiveObject(); StartCoroutine(DeactiveObject_WithDelay(obj)); } } touchedPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); animator.SetBool("Run", true); if (transform.position.x - touchedPos.x < 0) { transform.rotation = Quaternion.Euler(0, 0, 0); RaycastHit2D wall = Physics2D.Raycast(transform.position, Vector2.right, 1.5f, LayerMask.GetMask("Wall")); if (wall.collider == null) { transform.Translate(Vector2.right * speed * Time.deltaTime); } } else if (transform.position.x - touchedPos.x > 0) { transform.rotation = Quaternion.Euler(0, 180, 0); RaycastHit2D wall = Physics2D.Raycast(transform.position, Vector2.left, 1.5f, LayerMask.GetMask("Wall")); if (wall.collider == null) { transform.Translate(Vector2.right * speed * Time.deltaTime); } } } if (Input.GetMouseButtonUp(0) || EventSystem.current.IsPointerOverGameObject()) { animator.SetBool("Run", false); } }
public IEnumerator DeactiveObject_WithDelay(PrologueObject obj) { yield return(new WaitForSeconds(4)); obj.DeactiveObject(); }