Exemplo n.º 1
0
    public void OnDrawGizmos()
    {
        if (manager == null)
        {
            return;
        }
        Gizmos.color = Color.red;
        for (int x = 0; x < manager.CrossPoints._points.GetLength(0); x++)
        {
            for (int y = 0; y < manager.CrossPoints._points.GetLength(1); y++)
            {
                if (manager.CrossPoints._points [x, y] != null)
                {
                    Gizmos.DrawSphere(manager.CrossPoints._points [x, y].position, 0.1f);
                }
                else
                {
                    Debug.Log(x + "-" + y);
                }
            }
        }

        Gizmos.color = Color.white;

        CrossPoints.Point p = manager.CrossPoints._points [X, Y];
        Gizmos.DrawSphere(p.position, 0.1f);

        Gizmos.color = Color.blue;
        Gizmos.DrawLine(p.position, p.UpLeft.transform.position);
        if (p.LeftCross != null)
        {
            Gizmos.DrawSphere(p.LeftCross.position, 0.1f);
        }

        Gizmos.color = Color.yellow;
        Gizmos.DrawLine(p.position, p.UpRight.transform.position);
        if (p.RightCross != null)
        {
            Gizmos.DrawSphere(p.RightCross.position, 0.1f);
        }

        Gizmos.color = Color.green;
        Gizmos.DrawLine(p.position, p.DownLeft.transform.position);
        if (p.UpCross != null)
        {
            Gizmos.DrawSphere(p.UpCross.position, 0.1f);
        }

        Gizmos.color = Color.cyan;
        Gizmos.DrawLine(p.position, p.DownRight.transform.position);
        if (p.DownCross != null)
        {
            Gizmos.DrawSphere(p.DownCross.position, 0.1f);
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            direction = Direction.UP;
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            direction = Direction.DOWN;
        }
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            direction = Direction.LEFT;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            direction = Direction.RIGHT;
        }
        else
        {
            direction = Direction.IDLE;
        }

        if (direction != Direction.IDLE)
        {
            if (direction != lastDirectionType)
            {
                delta = 0;
            }
            striteTime += Time.fixedDeltaTime * 20 * speed;
            int s = Mathf.Cos(striteTime) > 0 ? 0 : 1;

            lastDirectionType = direction;
            float d = Time.deltaTime * speed;
            delta = delta + d;
            Vector2 newPos = point.position;
            switch (direction)
            {
            case Direction.DOWN:
                sp.sprite = down[s];
                if (point.DownCross != null)
                {
                    newPos += new Vector2(0, -delta);
                }
                else
                {
                    delta = 0;
                }
                break;

            case Direction.UP:
                sp.sprite = up[s];
                if (point.UpCross != null)
                {
                    newPos += new Vector2(0, delta);
                }
                else
                {
                    delta = 0;
                }
                break;

            case Direction.RIGHT:
                sp.sprite = right[s];
                if (point.RightCross != null)
                {
                    newPos += new Vector2(delta, 0);
                }
                else
                {
                    delta = 0;
                }
                break;

            case Direction.LEFT:
                sp.sprite = left[s];
                if (point.LeftCross != null)
                {
                    newPos += new Vector2(-delta, 0);
                }
                else
                {
                    delta = 0;
                }
                break;
            }
            if (delta >= 1.0f)
            {
                switch (direction)
                {
                case Direction.DOWN:
                    point = point.DownCross;
                    break;

                case Direction.UP:
                    point = point.UpCross;
                    break;

                case Direction.RIGHT:
                    point = point.RightCross;
                    break;

                case Direction.LEFT:
                    point = point.LeftCross;
                    break;
                }
                delta -= 1.0f;
            }
            transform.position = newPos;
        }
    }