コード例 #1
0
    private void Start()
    {
        Debug.Log("Game_Handler.Start");


        GameObject gameObject = new GameObject("Pipe", typeof(SpriteRenderer));

        gameObject.GetComponent <SpriteRenderer>().sprite = Game_Assets.GetInstance().pipeHeadSprite;
    }
コード例 #2
0
    //.............................................................................
    private void CreatePipe(float height, float xPosition, bool createBottom)
    {
        // pipe head setting

        Transform pipeHead = Instantiate(Game_Assets.GetInstance().pfPipeHead);
        float     pipeHeadYPosition;

        if (createBottom)
        {
            pipeHeadYPosition = -CAMERA_ORTHO_SIZE + height - PIPE_HEAD_HEIGHT * 0.5f;
        }
        else
        {
            pipeHeadYPosition = +CAMERA_ORTHO_SIZE - height + PIPE_HEAD_HEIGHT * 0.5f;
        }

        pipeHead.position = new Vector3(xPosition, pipeHeadYPosition);

        //setting body (pipebody)
        Transform pipeBody = Instantiate(Game_Assets.GetInstance().pfPipeBody);

        float pipeBodyYPosition;

        if (createBottom)
        {
            pipeBodyYPosition = -CAMERA_ORTHO_SIZE;
        }
        else
        {
            pipeBodyYPosition   = +CAMERA_ORTHO_SIZE;
            pipeBody.localScale = new Vector3(1, -1, 1);
        }
        pipeBody.position = new Vector3(xPosition, pipeBodyYPosition);

        SpriteRenderer pipeBodySpriteRenderer = pipeBody.GetComponent <SpriteRenderer>();

        pipeBodySpriteRenderer.size = new Vector2(PIPE_WIDTH, height);

        BoxCollider2D pipeBodyBoxCollider = pipeBody.GetComponent <BoxCollider2D>();

        pipeBodyBoxCollider.size   = new Vector2(PIPE_WIDTH, height);
        pipeBodyBoxCollider.offset = new Vector2(0f, height * .5f);


        Pipe pipe = new Pipe(pipeHead, pipeBody, createBottom);

        pipeList.Add(pipe);
    }