Exemplo n.º 1
0
    void AddNonPlayerSnakeSegment(int id)
    {
        if (ValidateNPID(id))
        {
            GameObject npSnake = npTargets[id].parent.gameObject;

            NPSnakeHead snakeHeadScript = npSnake.GetComponent <NPSnakeHead>();

            GameObject newSegment = GetSegment(npSnake.transform.parent);

            var newColor = snakeHeadScript.snakeData.color;
            newColor.a = GlobalConsts.SEGMENT_TRANSPARINCY;
            newSegment.GetComponent <SpriteRenderer>().color        = newColor;
            newSegment.GetComponent <TrailRenderer>().colorGradient = GetGradient(snakeHeadScript.snakeData.color);
            snakeHeadScript.segments.Add(newSegment);
            snakeHeadScript.Resize();
        }
    }
Exemplo n.º 2
0
    void SpawnSnake(SnakeData snake)
    {
        GameObject snakeContainer = GetNPSnake(snake.name, snake.id);

        GameObject newHead = snakeContainer.transform.GetChild(0).gameObject;

        //Non player snakes follow their targets for lerping reasons
        Transform target = newHead.transform.GetChild(0);

        NPSnakeHead snakeHeadManager = newHead.GetComponent <NPSnakeHead>();

        newHead.transform.GetChild(1).gameObject.GetComponentInChildren <Text>().text = snake.name;

        snakeHeadManager.snakeData = snake;
        //Set all nessary data for new snake
        newHead.transform.GetComponent <SpriteRenderer>().color = snake.color;
        newHead.transform.position = snake.pos;
        //newHead.transform.up = snake.dir;
        target.position     = snake.pos;
        target.transform.up = snake.dir;


        //Spawn all body segments based on snake length
        for (int i = 0; i < snake.length - 1; i++)
        {
            GameObject newSegment = GetSegment(snakeContainer.transform);

            var newColor = snake.color;
            newColor.a = GlobalConsts.SEGMENT_TRANSPARINCY;
            newSegment.GetComponent <SpriteRenderer>().color        = newColor;
            newSegment.GetComponent <TrailRenderer>().colorGradient = GetGradient(snake.color);
            snakeHeadManager.segments.Add(newSegment);
        }

        snakeHeadManager.Resize();
        //Add the new snake created to the list of snakes
        npTargets.Add(snake.id, target);
    }