Exemplo n.º 1
0
        public void AddBodyItem()
        {
            GameObject bodyItem = GameObject.Instantiate(bodyBlockItem, statusesTail[statusesTail.Count - 1].pos,
                                                         Quaternion.identity, transform);

            StatusTail statusTail = new StatusTail();

            statusTail.pos      = bodyItem.transform.position;
            statusTail.rotation = statusesTail[statusesTail.Count - 1].rotation;
            statusesTail.Add(statusTail);
            tail.Add(bodyItem);
        }
Exemplo n.º 2
0
        void Start()
        {
            startAnimation  = snakeHead.GetComponent <Animation>();
            defaultPosition = transform.position;
            snakeHead.transform.Rotate(Vector3.back, -90f);
            colliderSnakeHead = snakeHead.GetComponent <BoxCollider>();
            startGame         = false;
            direction         = Vector2.right;

            StatusTail statusTail = new StatusTail();

            statusTail.pos      = snakeHead.transform.position;
            statusTail.rotation = snakeHead.transform.rotation;
            statusesTail.Add(statusTail);
        }
Exemplo n.º 3
0
        public void Restart()
        {
            foreach (GameObject bodyItem in tail)
            {
                Destroy(bodyItem);
            }
            tail.Clear();
            statusesTail.Clear();

            StartMove();
            StatusTail statusTail = new StatusTail();

            statusTail.pos      = snakeHead.transform.position;
            statusTail.rotation = snakeHead.transform.rotation;
            statusesTail.Add(statusTail);
        }
Exemplo n.º 4
0
        void TailRender()
        {
            float distance = ((Vector2)snakeHead.transform.position - statusesTail[0].pos).magnitude;

            if (distance > bodyBlockItemDiameter)
            {
                Vector2 optimizeDirection = ((Vector2)snakeHead.transform.position - statusesTail[0].pos).normalized;

                StatusTail statusTail = new StatusTail();
                statusTail.pos      = statusesTail[0].pos + optimizeDirection * bodyBlockItemDiameter;
                statusTail.rotation = statusesTail[0].rotation;
                statusesTail.Insert(0, statusTail);
                statusesTail.RemoveAt(statusesTail.Count - 1);
                distance -= bodyBlockItemDiameter;
            }

            for (int i = 0; i < tail.Count; i++)
            {
                tail[i].transform.position =
                    Vector2.Lerp(statusesTail[i + 1].pos, statusesTail[i].pos, distance / bodyBlockItemDiameter);
                tail[i].transform.rotation = statusesTail[i + 1].rotation;
            }
        }