/** * Use this for initialization */ void Start() { GameObject mouthGUI = GameObject.Find("MouthGUI"); // find the mouth GUI score = mouthGUI.GetComponent <MouthScore>(); // get the score off the gui foodSpawner = GameObject.Find("FoodSpawner").GetComponent <SpawnFood>(); // find the foodSpawner }
IEnumerator StartGame(StartGame startMessage) { id = startMessage.id; SceneManager.LoadScene("game"); yield return(new WaitForFixedUpdate()); //Wait a fixed update cycle to make sure that all new objects can init MessageSystem.instance.DispatchMessage(new CreatePlayer(startMessage.playerName, startMessage.playerColor, startMessage.startPos, startMessage.startDir)); foreach (var snake in startMessage.otherSnakes) { SpawnNPSnake spawnMessage = new SpawnNPSnake(snake); MessageSystem.instance.DispatchMessage(spawnMessage); } foreach (var food in startMessage.foodInGame) { SpawnFood spawnMessage = new SpawnFood(food); MessageSystem.instance.DispatchMessage(spawnMessage); } gameRunning = true; //Now start doing all the game processes since things are inited MessageSystem.instance.DispatchMessage(new GameRunning()); }
// Use this for initialization void Start() { food = FindObjectOfType <SpawnFood>(); alive = true; snakeMaterial.SetColor("_Color", Color.white); snakeSegmentPrefab.localScale = Vector3.one * nodeSize; gridBounds = new Vector2Int(); direction = Vector2Int.up; for (float y = -gridSize / 2f; y < (gridSize / 2f) + gridSpacing; y += gridSpacing) { gridBounds += new Vector2Int(1, 1); for (float x = -gridSize / 2f; x < (gridSize / 2f) + gridSpacing; x += gridSpacing) { coordinates.Add(new Vector2(x, y)); } } for (int i = 0; i < gridBounds.x; i++) { for (int j = 0; j < gridBounds.y; j++) { openIndexes.Add(new Vector2Int(i, j)); } } snakeHeadIndex = new Vector2Int(gridBounds.x / 2, gridBounds.y / 2); snakeIndexes.Add(snakeHeadIndex); openIndexes.Remove(snakeHeadIndex); snakeSegment.Enqueue(Instantiate(snakeSegmentPrefab, coordinates[snakeHeadIndex.x + snakeHeadIndex.y * gridBounds.x], Quaternion.identity, snakeSegmentHolder)); StartCoroutine(MovementUpdater()); }
void MakeInstance() { if (instance == null) { instance = this; } }
void Awake() { // Register the singleton if (Instance != null) { Debug.LogError("Multiple instances of SpecialEffectsHelper!"); } Instance = this; }
// Use this for initialization void Start() { HeadSprite.GetComponent <SpriteRenderer>().color = GameController.control.PlayerData.SnakeColor; lichaamPrefab.GetComponent <SpriteRenderer>().color = GameController.control.PlayerData.SnakeColor; foodSpawner = GetComponent <SpawnFood>(); // Move the Snake every 300ms InvokeRepeating("Move", 0.3f, snelheid); }
void Start() { PV = GetComponent <PhotonView>(); spawnFood = GetComponent <SpawnFood>(); joy = FindObjectOfType <Joystick>(); boost = FindObjectOfType <Booster>(); gameSet = FindObjectOfType <GameSetup>(); Debug.Log(gameSet.Master.tag.ToString()); Debug.Log(PhotonNetwork.IsMasterClient.ToString()); }
void Start() { //component that plays a sound effect when food is eaten eatSound = GetComponent <AudioSource>(); //snake width width = (int)GetComponent <BoxCollider2D>().size.x; waitAfterPause = baseSpeed; foodScript = gameManager.GetComponent <SpawnFood>(); bordersKill = GameOptions.bordersKill; }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } }
void Start() { //Mutes sound according to sound preference soundPlayer = this.GetComponent <AudioSource>(); if (!GameOptions.soundOn) { SwitchSound(); } //gets script that controls food foodScript = this.GetComponent <SpawnFood>(); extravaganzaDuration = foodScript.extravaganzaDuration; }
private void OnTriggerEnter2D(Collider2D collision) { Debug.Log("OnTriggerEnter2D"); if (collision.name.StartsWith("Food")) { ate = true; Destroy(collision.gameObject); SpawnFood.EatOne(); } else { GameController.FailGame(); audioSource2.clip = audioClips [3]; audioSource2.Play(); } }
private void OnTriggerEnter2D(Collider2D collision) { Debug.Log("OnTriggerEnter2D"); //CAN BE IMPROVE WITH TAG PROPERTY if (collision.name.StartsWith("Food")) { ate = true; Destroy(collision.gameObject); SpawnFood.EatOne(); } else if (collision.tag.Contains("Border")) { GameController.FailGame(); //TODO:YOU LOSE SCREEN } }
public void GameStart_S() { Text.GetComponent <TimeBoxScript>().timeCountStart(time); SpawnFood spfood = camera.GetComponent <SpawnFood>(); spfood.FoodSpawnStart(); for (int i = 0; i < person_num; i++) { if (WormLightList[i] != null) { WormLightList[i].SetActive(false); } } WorldLight.SetActive(true); SFXplayer.PlayGameBGM(); }
private void SpawnFood(SpawnFood food) { GameObject newFood; if (deadFoodObjects.Count <= 0) { newFood = Instantiate(foodPrefab, transform); } else { newFood = deadFoodObjects.Dequeue(); newFood.SetActive(true); } newFood.name = "Food " + food.id; foodObjects.Add(food.id, newFood); newFood.transform.position = food.pos; }
void Start() { uiManager = FindObjectOfType <UIManager>(); spawner = GetComponentInChildren <SpawnFood>(); foreach (Enemy enemy in enemies) { enemy.IgnorePlayer(); remainingEnemies++; } foreach (Enemy enemy in leapEnemies) { enemy.gameObject.SetActive(false); remainingEnemies++; } spawner.gameObject.SetActive(false); cameraBehaviour = FindObjectOfType <CameraBehaviour>(); }
// Use this for initialization private void Start() { GameCamera = GameObject.Find("Camera"); SpawnFoodScript = GameCamera.GetComponent <SpawnFood>(); rb = gameObject.GetComponent <Rigidbody>(); rb.transform.localScale = new Vector3(Global.head_size, Global.head_size, Global.head_size); tailPrefab.transform.localScale = new Vector3(Global.tail_size, Global.tail_size, Global.tail_size); WormLight = GameObject.Find("BotLight[" + Head_index + "]"); Debug.Log("Head_index : " + Head_index + ", is light exist : " + (WormLight != null)); thisMesh = gameObject.GetComponent <MeshRenderer>(); for (int i = 0; i < 1; i++) { TailCreate(rb.position); } headspeed_mult = Global.init_botHeadSpeed; }
// I changed the "Layer" of the "Head" in "SNAKE" to SNAKE (using unity editor) // So that if a collison happens in the Head, it will pass that signal to the nearest Rigidbody, in this case it is the "SNAKE"'s Rigidbody // I also turned off the Sphere Collider in Sphere Prefab (using unity-editor) // So that if the tail touches the food it DO NOT destroy the food void OnCollisionEnter(Collision collision) { ifColided = true; // Create an instance, which links to SpawnFood.cs script // Because SpawnFood.cs script is attached to "Camera", we find "Camera" and get the component SpawnFood foodController = platform.GetComponent <SpawnFood>(); Debug.Log("You collided with " + collision.gameObject); if (collision.gameObject.tag == "Food") { Destroy(collision.gameObject); AddBody(); foodController.LetSpawnFood(); } if (collision.gameObject.tag == "Obstacle") { ifAlive = false; } }
void Start() { _foodSpawner = GetComponentInParent <SpawnFood>(); }
void Start() { foodController = platform.GetComponent <SpawnFood>(); StartGame(initLength); }
// Use this for initialization void Start() { sFood = GameObject.Find("Game Manager").GetComponent<SpawnFood>(); }
// Use this for initialization void Start() { sFood = GameObject.Find("Game Manager").GetComponent <SpawnFood>(); }
private void Move() { if (_dirList.Count == 0) { return; } ArrayPosHandler oldPosInArray = _currPosInArray, newPosInArray; if (_dirList.Count > 1) { newPosInArray = _currPosInArray + _dirList.Last(); _dirList.RemoveAt(_dirList.Count - 1); } else { newPosInArray = _currPosInArray + _dirList.First(); } ArrayPosHandler inputValue = newPosInArray - _currPosInArray; if (_inputs.Count > 0) { _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y)); } else { _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y)); _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y)); } if (ArrayPosHandler.IsLeftBorderCrossed(newPosInArray)) { _currPosInArray = new ArrayPosHandler(_currPosInArray.x, _gs.gameArray.GetLength(1) - 1); } else if (ArrayPosHandler.IsRightBorderCrossed(newPosInArray, _gs.gameArray.GetLength(1) - 1)) { _currPosInArray = new ArrayPosHandler(_currPosInArray.x, 0); } else if (ArrayPosHandler.IsTopBorderCrossed(newPosInArray)) { _currPosInArray = new ArrayPosHandler(_gs.gameArray.GetLength(0) - 1, _currPosInArray.y); } else if (ArrayPosHandler.IsBottomBorderCrossed(newPosInArray, _gs.gameArray.GetLength(0) - 1)) { _currPosInArray = new ArrayPosHandler(0, _currPosInArray.y); } else { _currPosInArray = newPosInArray; } transform.position = _gs.GetPosition(_currPosInArray); MoveEvent?.Invoke(); _steps.Insert(0, _currPosInArray); _gs.ChangGameArray(_currPosInArray, 1); if (_ateFood) { EatEvent?.Invoke(); SpawnFood?.Invoke(); _gs.ChangGameArray(oldPosInArray, 2); SpawnTail(oldPosInArray); _ateFood = false; } else if (_ateBonus) { BonusEvent?.Invoke(); SpawnTail(oldPosInArray); _gs.ChangGameArray(oldPosInArray, 2); _ateBonus = false; } else if (_tail.Count > 0) { TailLastToFirst(oldPosInArray); } else { _gs.ChangGameArray(oldPosInArray, 0); } if (_steps.Count > 2) { _steps.RemoveAt(_steps.Count - 1); } if (_inputs.Count > 2) { _inputs.RemoveAt(_inputs.Count - 1); } }
void OnDisable() { instance = null; }
// Use this for initialization void Start() { sFood = GameObject.Find("Game Manager").GetComponent<SpawnFood>(); scoreSYS = GameObject.Find("Game Manager").GetComponent<ScoreSystem>(); }
// Use this for initialization void Start() { sFood = GameObject.Find("Game Manager").GetComponent <SpawnFood>(); scoreSYS = GameObject.Find("Game Manager").GetComponent <ScoreSystem>(); }