GameM









How do I use Game M
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: SideWalls.cs Copy
7  void OnTriggerEnter2D(Collider2D hitInfo) {
8   if (hitInfo.name == "Ball")
9   {
10    string wallName = transform.name;
11    GameManager.Score (wallName);
12    hitInfo.gameObject.SendMessage ("RestartGame", 1, SendMessageOptions.RequireReceiver);
13   }
14  }
File name: SwitchAngle.cs Copy
62  void Start () {
63   int cameraView = PlayerPrefs.GetInt(GameManager.CAMERA_VIEW,0);
64   angleType = (cameraView == 1) ? AngleType._3D : AngleType._2D;
65   rotateCamera = GetComponent();
66   LoadAngleType();
67  }
File name: Grid.cs Copy
206  public void SpawnPiece(GridCoords coords, GameObject piece, float yRotation, PlayerType playerType) {
207   Node pieceNode = GetNodeAt(coords.row, coords.col);
208
209   Vector3 pRotation = piece.transform.rotation.eulerAngles;
210   Quaternion newPRotation = Quaternion.Euler(pRotation.x, yRotation, pRotation.z);
211
212   GameObject pieceObject = Instantiate(piece, pieceNode.transform.position + Vector3.up * 1.2f, newPRotation) as GameObject;
213   pieceObject.transform.localScale = Vector3.zero; //for scaling in start from zero
214   Piece pieceScript = pieceObject.GetComponent(typeof(Piece)) as Piece;
215
216   //assign mat and player type
217   Material mat = null;
218   GCPlayer player = null;
219   switch (playerType) {
220    case PlayerType.P1:
221     mat = GameManager.Instance.PieceP1;
222     player = GameManager.Instance.P1;
223     break;
224    case PlayerType.P2:
225     mat = GameManager.Instance.PieceP2;
226     player = GameManager.Instance.P2;
227     break;
228   }
229   pieceObject.GetComponent().material = mat;
230   player.AddPieces(pieceScript);
231   pieceScript.PieceMovement = Creator.CreatePieceMovement(pieceScript.MovementType, player, pieceScript);
232
233   if(pieceScript) //if exists type then scale
234    pieceScript.ScaleIn(Random.Range(0f,1f),Random.Range(1f,2f),piece.transform.localScale);
235
236
237   pieceScript.UpdateNode(pieceNode);
238  }
File name: Node.cs Copy
35  public void HighlightMove() {
36   if (renderer.sharedMaterial != origMaterial) return;
37   SetMaterial(GameManager.Instance.HighlightMoveMaterial);
38  }
File name: Node.cs Copy
40  public void HighlightEat() {
41   if (renderer.sharedMaterial != origMaterial) return;
42   SetMaterial(GameManager.Instance.HighlightEatMaterial);
43  }
File name: Node.cs Copy
45  public void HighlightCheck() {
46   if (renderer.sharedMaterial != origMaterial) return;
47   SetMaterial(GameManager.Instance.HighlightCheckMaterial);
48  }
File name: Node.cs Copy
50  public void UnhighlightMove() {
51   Unhiglight(GameManager.Instance.HighlightMoveMaterial);
52  }
File name: Node.cs Copy
54  public void UnhighlightEat() {
55   Unhiglight(GameManager.Instance.HighlightEatMaterial);
56  }
File name: Node.cs Copy
58  public void UnhighlightCheck() {
59   Unhiglight(GameManager.Instance.HighlightCheckMaterial);
60  }
File name: GameManager.cs Copy
172  void Update () {
173
174#if UNITY_EDITOR
175   if (Input.GetKeyDown(KeyCode.Z)) {
176    GameManager.Instance.GameState.Checkmate();
177    GameOver(p1,GameOverType.CHECKMATE); //TODO delete
178   } else if (Input.GetKeyDown(KeyCode.X)) {
179    GameManager.Instance.GameState.Checkmate();
180    GameOver(p2,GameOverType.CHECKMATE); //TODO delete
181   } else if (Input.GetKeyDown(KeyCode.C)) {
182    GameManager.Instance.GameState.Stalemate();
183    GameOver(p2,GameOverType.STALEMATE);
184   }
185#endif
186
187   if (!ready) return;
188   if (gameState.IsGameOver) return;
189
190
191   //EXPERIMENT_TIMER
192   if (whiteTurn) {
193    whiteTimer -= Time.deltaTime;
194    if (whiteTimer < 0 ) {
195     whiteTimer = 0;
196     GameManager.Instance.GameState.OutOfTime();
197     GameOver(p2, GameOverType.OUT_OF_TIME);
198    }
199    UpdateWhiteTimer();
200   } else {
201    blackTimer -= Time.deltaTime;
202    if (blackTimer < 0 ) {
203     blackTimer = 0;
204     GameManager.Instance.GameState.OutOfTime();
205     GameOver(p1, GameOverType.OUT_OF_TIME);
206    }
207    UpdateBlackTimer();
208   }
209  }

Download file with original file name:GameM

GameM 108 lượt xem

Gõ tìm kiếm nhanh...