Helpful tips in creating functunalities

Here are some tips in how to create a new functionality, according to me: If you have something that is not so simple, write pseudocode...

Sunday, December 23, 2018

How I've used a scrolling ability system

So I have 3 connected boxes showing these 3 abilities. I have made them scroll. Here is my code:

if (Input.GetKeyDown(KeyCode.RightArrow) && skillSize > 0)
        {
            List<GameObject> A = new List<GameObject>();
            A[skill.Count - 1] = skill[0];
            for (int a = 0; a < skill.Count - 1; a++)
            {
                A[a] = skill[a + 1];
            }
            skill = A;
            if (skill.Count == 1)
            {
                skill[0].transform.localPosition = pipeHovered.transform.localPosition;
                return;
            }
            else if (skill.Count == 2)
            {
                skill[0].transform.localPosition = pipeStaticLeft.transform.localPosition;
                skill[1].transform.localPosition = pipeHovered.transform.localPosition;
                return;
            }
            else
            {
                skill[0].transform.localPosition = pipeStaticLeft.transform.localPosition;
                skill[1].transform.localPosition = pipeHovered.transform.localPosition;
                skill[2].transform.localPosition = pipeStaticRight.transform.localPosition;
 
            }
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow) && skillSize > 0)
        {
            List<GameObject> A = new List<GameObject>();
            A[0] = skill[skill.Count - 1];
            for (int a = skill.Count - 1; a > 0; a--)
            {
                A[a] = skill[a - 1];
            }
            skill = A;
            if (skill.Count == 1)
            {
                skill[0].transform.localPosition = pipeHovered.transform.localPosition;
                return;
            }
            else if (skill.Count == 2)
            {
                skill[0].transform.localPosition = pipeStaticLeft.transform.localPosition;
                skill[1].transform.localPosition = pipeHovered.transform.localPosition;
                return;
            }
            else
            {
                skill[0].transform.localPosition = pipeStaticLeft.transform.localPosition;
                skill[1].transform.localPosition = pipeHovered.transform.localPosition;
                skill[2].transform.localPosition = pipeStaticRight.transform.localPosition;
            }
        }

No comments:

Post a Comment

The Art of Game Development

The Art of Game Development
A Guide for Beginners (eBook)