Ejemplo n.º 1
0
    ///<summary>Adds a new node to the snake for one turn, with animation if necessary.</summary>
    public void grow(float timeToMove, bool shouldMoveSmoothly)
    {
        // like the move function, but instantiates a new node as the head instead of moving the tail up
        SnakeNode newHead = Instantiate(this.snakeNodePrefab, this.head.transform.position, this.head.transform.rotation, this.gameOrigin.transform) as SnakeNode;

        newHead.setDirection(this.head.getDirection());
        newHead.setCoordinates(this.head.getCoordinates());
        this.nodes.Add(newHead);

        newHead.StartCoroutine(newHead.moveToCoordinates(this.head.coordinatesOfNextNode(), timeToMove, shouldMoveSmoothly));

        this.head.setNodeBefore(newHead);
        this.head = newHead;
    }