Exemplo n.º 1
0
    void FixedUpdate()
    {
        if (Input.GetMouseButtonDown(0) && GlobalInput.verifyInput(InputType.GameMap))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                moveTo(hit.transform.position.x, hit.transform.position.y);
                if (hit.collider.gameObject.GetComponent <ItemBase>() != null)
                {
                    //Debug.Log("ITEM");
                    _targetType = ObjectType.Item;
                    _target     = hit.collider.gameObject;
                }
                else if (hit.collider.gameObject.GetComponent <TileChanges>() != null)
                {
                    //Debug.Log("TILE");
                    if (hit.collider.gameObject.GetComponent <ActionTile>() != null)
                    {
                        _targetType = ObjectType.Tile;
                        _target     = hit.collider.gameObject;
                    }
                }
                else if (hit.collider.gameObject.GetComponent <GameCharacterController>() != null)
                {
                    //Debug.Log("CHARACTER");
                    _targetType = ObjectType.Character;
                    _target     = hit.collider.gameObject;
                }
            }
        }

        if (Mathf.Abs(_targetPos.x - this.transform.position.x) < 1)
        {
            this.rigidbody.velocity = new Vector3(0, this.rigidbody.velocity.y, 0);
        }
        else
        {
            if (_targetPos.x - this.transform.position.x < 0)
            {
                this.rigidbody.velocity = new Vector3(-charSpeed, this.rigidbody.velocity.y, 0);
                scriptAnim.moveLeft();
            }
            else
            {
                this.rigidbody.velocity = new Vector3(charSpeed, this.rigidbody.velocity.y, 0);
                scriptAnim.moveRight();
            }
        }
        if (Mathf.Abs(_targetPos.y - this.transform.position.y) < 1)
        {
            this.rigidbody.velocity = new Vector3(this.rigidbody.velocity.x, 0, 0);
        }
        else
        {
            if (_targetPos.y - this.transform.position.y < 0)
            {
                this.rigidbody.velocity = new Vector3(this.rigidbody.velocity.x, -charSpeed, 0);
                scriptAnim.moveDown();
            }
            else
            {
                this.rigidbody.velocity = new Vector3(this.rigidbody.velocity.x, charSpeed, 0);
                scriptAnim.moveUp();
            }
        }

        if (this.rigidbody.velocity.x == 0 && this.rigidbody.velocity.y == 0)
        {
            scriptAnim.hasAnim = false;
        }
    }