- How to play screen snake how to#
- How to play screen snake update#
- How to play screen snake free#
Main Camera variable is self-explanatory, assign the default Main Camera. Attach SC_SnakeGameGenerator.cs script to _GameGenerator ObjectĪs you will notice SC_SnakeGameGenerator have some variables that need to be assigned:. If (fruitBlockIndex Create Empty) and name it "_GameGenerator" Int newCoordinate = snakeCoordinates - 1 Int newCoordinate = snakeCoordinates + 1 Int newCoordinate = snakeCoordinates - areaResolution Int newCoordinate = snakeCoordinates + areaResolution GameBlocks].transform.localEulerAngles = new Vector3(90, (snakeDirection = Direction.Down ? 180 : 0), 0) Int newCoordinate = snakeCoordinates + (snakeDirection = Direction.Down ? -1 : 1) If (snakeDirection = Direction.Up & (snakeCoordinates + 1) % areaResolution = 0)Įlse if (snakeDirection = Direction.Down & (snakeCoordinates + 1) % areaResolution = 1) GameBlocks].transform.localEulerAngles = new Vector3(90, (snakeDirection = Direction.Left ? -90 : 90), 0) Įlse if (snakeDirection = Direction.Up || snakeDirection = Direction.Down) If (snakeCoordinates.Contains(newCoordinate)) Int newCoordinate = snakeCoordinates + (snakeDirection = Direction.Left ? -areaResolution : areaResolution) If (timeTmp = (gameBlocks.Length - areaResolution)) GameBlocks].transform.localEulerAngles = new Vector3(90, 90, 0) SnakeCoordinates.Add(firstlock - (areaResolution * 2)) SnakeCoordinates.Add(firstlock - areaResolution) Int firstlock = Random.Range(0, areaResolution - 1) + (areaResolution * 3) MainStyle.alignment = TextAnchor.MiddleCenter MainCamera.orthographicSize = / 2 * differenceInSize MainCamera.orthographicSize = / 2 įloat differenceInSize = targetRatio / screenRatio = new Vector3(90, 0, 0) įloat screenRatio = (float)Screen.width / (float)Screen.height įloat targetRatio = / Scale the MainCamera to fit the game blocks TargetBounds.Encapsulate(gameBlocks.bounds)
How to play screen snake update#
Start is called before the first frame update Game area resolution, the higher number means more blocksĮnum Direction ĭirection snakeDirection = Direction.Right Public class SC_SnakeGameGenerator : MonoBehaviour
How to play screen snake free#
SC_SnakeGameGenerator.cs //You are free to use this script in Free or Commercial projects Unity version used in this tutorial: Unity 2018.3.0f2 (64-bit) Step 1: Create the Scriptīeing a "One Script Game" this tutorial only requires 1 script:
How to play screen snake how to#
In this post, I will be showing how to create a classic Snake Game in Unity 3D.