public void InitGeneralCharacter(GameObject animalCharacter, long playerID, string playerName, int cellX, int cellY) { characterInstance = Instantiate(animalCharacter, transform.position, transform.rotation) as GameObject; var animationScript = characterInstance.GetComponent <CharacterAnimController>(); animationScript.EnemyPlayer = !isSelf; float spawnX = ZooMap.GetHorizontalPos(cellX); float spawnY = ZooMap.GetVerticalPos(cellY); animationScript.SpawnCharacter(spawnX, spawnY); if (isSelf) { characterInstance.gameObject.tag = "Player"; } characterInstance.gameObject.name = "" + playerID; // Instantiate name tk2dTextMesh nameScript = characterInstance.transform.Find("HUD_Name").GetComponent <tk2dTextMesh>(); if (nameScript != null) { nameScript.text = playerName; } }
public void PlantBomb(float horizontalCell, float verticalCell) { // If player is still moving, don't plant the bomb //if(isStillMoving) //{ // return; //} //float verticalCell = ZooMap.GetVerticalCell(transform.position.y); //float horizontalCell = ZooMap.GetHorizontalCell(transform.position.x); float verticalPos = ZooMap.GetVerticalPos(verticalCell); float horizontalPos = ZooMap.GetHorizontalPos(horizontalCell); //Vector3 bombPos = transform.position + new Vector3(0, 0, 0.01f); Vector3 bombPos = new Vector3(horizontalPos, verticalPos, 0.01f); GameObject bombInstance = Instantiate(bombGO, bombPos, transform.rotation) as GameObject; string bombId = (int) horizontalCell + "" + (int) verticalCell; string cellID = (int) horizontalCell + ":" + (int) verticalCell; if(bombDict.ContainsKey(bombId) == false) { bombDict.Add(bombId, bombInstance); // bomb is planted in the cell zooMapScript.UpdateCellWithBomb(cellID, true); m_bombLimit--; } }
public void PlantBomb(long serverPlayerID, float cellX, float cellY, long bombLeft) { GameObject characterObject = GameObject.Find("" + serverPlayerID); // If the player ID is me, then i update my own prefab bombleft if (characterObject) { CharacterAnimController playerController = characterObject.GetComponent <CharacterAnimController>(); playerController.PlantBomb(cellX, cellY); if (serverPlayerID == PlayerID) { GameObject hud = GameObject.Find("UnityHUDPrefab"); if (hud) { HUD hudScript = hud.GetComponent <HUD>(); hudScript.SetBombLeft(playerController.BombLimit); } // Play Sound SoundManager soundManager = GameObject.Find("SoundManager").GetComponent <SoundManager>(); soundManager.PlayPlantBombSound(new Vector3(ZooMap.GetHorizontalPos(cellX), ZooMap.GetVerticalPos(cellY), 0)); } } }
public void MoveRight(float originalCellX, float originalCellY, bool sendToServer) { if(previousDirection != DirectionType.Right) { UpdateRayCasting(DirectionType.Right); previousDirection = DirectionType.Right; } Vector3 startPoint = transform.position; float verticalCell = 0; float horizontalCell = 0; if(sendToServer) { verticalCell = ZooMap.GetVerticalCell(transform.position.y); horizontalCell = ZooMap.GetHorizontalCell(transform.position.x); } else { horizontalCell = originalCellX; verticalCell = originalCellY; } // exceed the map if( horizontalCell >= ZooMap.NumberofRows - 1 || isStillMoving) return; bool isObstacleAhead = ZooMap.IsObstacle((int) horizontalCell + 1, (int) verticalCell); if(isObstacleAhead) { Debug.Log ("Obstacle!!! is on right"); return; } float nextPosX = ZooMap.GetHorizontalPos(horizontalCell + 1); Vector3 endPoint = new Vector3(nextPosX, transform.position.y, transform.position.z); //transform.position = Vector3.Lerp(startPoint, endPoint, (speed * Time.deltaTime)); float time = ZooMap.cellWidth / speed; // time = distance over speed // client moves if(sendToServer) { clientSocketScript.SendMovementMessage(horizontalCell, verticalCell, "RIGHT", speed); SoundManager soundManager = GameObject.Find ("SoundManager").GetComponent<SoundManager>(); if(soundManager != null) soundManager.PlayMoveSound(transform.position); } StartCoroutine(MoveObject(transform, startPoint, endPoint, time, DirectionType.Right)); }
public void RespawnPlayer(float cellX, float cellY) { float horizontalPos = ZooMap.GetHorizontalPos(cellX); float verticalPos = ZooMap.GetVerticalPos(cellY); gameObject.transform.position = new Vector3(horizontalPos, verticalPos, gameObject.transform.position.z); }