Ejemplo n.º 1
0
        private void Interact(RaycastHit2D hit)
        {
            PrologueObject obj = hit.transform.GetComponent <PrologueObject>();

            obj.ActiveObject(gameObject);
            StartCoroutine(DeactiveObject_WithDelay(obj));
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        public IEnumerator DeactiveObject_WithDelay(PrologueObject obj)
        {
            yield return(new WaitForSeconds(4));

            obj.DeactiveObject();
        }