Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using NUnit.Framework.Interfaces;
- using Photon.Pun;
- using System.Collections;
- using System.Collections.Generic;
- using BEKStudio;
- using TMPro;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- namespace BEKStudio{
- public class GameController : MonoBehaviour{
- public static GameController Instance;
- public enum GameState{
- READY,
- WAIT,
- SWITCH_MASTER,
- WIN,
- LOSE
- };
- public GameState gameState;
- public Rigidbody2D playerPuck;
- public PhotonView playerPhotonView;
- public List<GameObject> homePucksCollected;
- public List<GameObject> awayPucksCollected;
- public List<GameObject> pucksCollected;
- public Sprite[] avatars;
- [Header("Top")]
- public TextMeshProUGUI topTotalBetText;
- public Image topHomeAvatar;
- public Image topHomeAvatarTimer;
- public TextMeshProUGUI topHomeNameText;
- public TextMeshProUGUI topHomeScoreText;
- public Image topAwayAvatar;
- public Image topAwayAvatarTimer;
- public TextMeshProUGUI topAwayNameText;
- public TextMeshProUGUI topAwayScoreText;
- public Transform topCoinParentForAnim;
- [Header("Toast Message")]
- public GameObject toastMessage;
- public TextMeshProUGUI toastMessageText;
- [Header("Settings")]
- public GameObject settingsScreen;
- public Image settingsBackground;
- public RectTransform settingsContinue;
- public RectTransform settingsMenu;
- public Slider playerSlider;
- public Slider opponentSlider;
- [Header("Puck")]
- public Puck[] allPucks;
- public float playerPuckMinX;
- public float playerPuckMaxX;
- [Header("Others")]
- public bool isPucksFixed;
- public bool shootAgain;
- string targetTag;
- public string masterClientTag;
- public float timer;
- public bool reduceTimer;
- public GameObject redPuck;
- public GameObject statusScreen;
- public Image statusBackground;
- public RectTransform statusPanel;
- public TextMeshProUGUI statusPanelText;
- public bool redPuckCollected;
- public bool practiceMode;
- public bool redPuckWaiting;
- void Awake(){
- if (Instance == null){
- Instance = this;
- }
- }
- void Start(){
- masterClientTag = "White";
- CheckTurn();
- homePucksCollected = new List<GameObject>();
- awayPucksCollected = new List<GameObject>();
- pucksCollected = new List<GameObject>();
- targetTag = (string)PhotonNetwork.LocalPlayer.CustomProperties["tag"];
- redPuck.SetActive(PhotonController.Instance.whichMode == "carrom");
- topTotalBetText.text = (PhotonController.Instance.roomEntryPice * 2).ToString("###,###,###");
- if (PhotonNetwork.PlayerList.Length == 2){
- topHomeNameText.text = PhotonNetwork.PlayerList[0].NickName;
- topHomeAvatar.sprite = avatars[(int)PhotonNetwork.PlayerList[0].CustomProperties["avatar"]];
- topAwayNameText.text = PhotonNetwork.PlayerList[1].NickName;
- topAwayAvatar.sprite = avatars[(int)PhotonNetwork.PlayerList[1].CustomProperties["avatar"]];
- } else{
- topHomeNameText.text = PhotonNetwork.PlayerList[0].NickName;
- topHomeAvatar.sprite = avatars[(int)PhotonNetwork.PlayerList[0].CustomProperties["avatar"]];
- topAwayNameText.text = "";
- topAwayAvatar.sprite = null;
- }
- if (practiceMode){
- topTotalBetText.text = "0";
- topAwayNameText.transform.parent.gameObject.SetActive(false);
- topHomeScoreText.transform.parent.gameObject.SetActive(false);
- }
- isPucksFixed = true;
- StartMessage();
- }
- void StartMessage(){
- if (practiceMode){
- statusPanelText.text = "YOU START";
- toastMessageText.text = "Practice Mode";
- } else if (targetTag == "White"){
- statusPanelText.text = "YOU START";
- toastMessageText.text = "Pot all white pucks to win the match";
- } else if (targetTag == "Black"){
- statusPanelText.text = "OPPONENT START";
- toastMessageText.text = "Pot all black pucks to win the match";
- }
- statusPanel.anchoredPosition = new Vector2(-940f, statusPanel.anchoredPosition.y);
- statusBackground.color = new Color(0, 0, 0, 0);
- statusScreen.SetActive(true);
- LeanTween.alpha(statusBackground.GetComponent<RectTransform>(), 0.5f, 0.5f);
- LeanTween.move(statusPanel, new Vector2(0, statusPanel.anchoredPosition.y), 0.3f).setDelay(0.5f)
- .setEase(LeanTweenType.easeOutBack).setOnComplete(() => {
- LeanTween.move(statusPanel, new Vector2(940, statusPanel.anchoredPosition.y), 0.3f).setDelay(1f)
- .setEase(LeanTweenType.easeInBack).setOnComplete(
- () => { statusScreen.SetActive(false); });
- });
- }
- void Update(){
- if (practiceMode) return;
- RunTimer();
- }
- void FixedUpdate(){
- if (gameState == GameState.READY || gameState == GameState.WAIT){
- isPucksFixed = GetPuckStatus();
- }
- }
- void RunTimer(){
- if (gameState != GameState.READY) return;
- if (reduceTimer){
- timer -= 1 * Time.deltaTime;
- }
- if (PhotonNetwork.InRoom){
- if (masterClientTag == "White"){
- topHomeAvatarTimer.fillAmount = Mathf.InverseLerp(0, Constants.PLAY_TIME_FOR_PLAYER, timer);
- } else{
- topAwayAvatarTimer.fillAmount = Mathf.InverseLerp(0, Constants.PLAY_TIME_FOR_PLAYER, timer);
- }
- }
- if (timer <= 0 && playerPhotonView.IsMine){
- gameState = GameState.WAIT;
- PlayerPuck.Instance.isTouch = false;
- PlayerPuck.Instance.arrow.SetActive(false);
- PlayerPuck.Instance.tutorial.SetActive(false);
- PlayerPuck.Instance.tutorialShowDelay = 2f;
- shootAgain = false;
- StartCoroutine(WaitForPucks());
- }
- }
- public void SettingsBtn(){
- if (gameState == GameState.WIN || gameState == GameState.LOSE) return;
- settingsContinue.anchoredPosition = new Vector2(-940f, settingsContinue.anchoredPosition.y);
- settingsMenu.anchoredPosition = new Vector2(-940f, settingsMenu.anchoredPosition.y);
- settingsBackground.color = new Color(0, 0, 0, 0);
- settingsScreen.SetActive(true);
- LeanTween.alpha(settingsBackground.GetComponent<RectTransform>(), 0.75f, 0.25f);
- LeanTween.move(settingsContinue, new Vector2(0, settingsContinue.anchoredPosition.y), 0.3f).setDelay(0.25f)
- .setEase(LeanTweenType.easeOutBack);
- LeanTween.move(settingsMenu, new Vector2(0, settingsMenu.anchoredPosition.y), 0.3f).setDelay(0.5f)
- .setEase(LeanTweenType.easeOutBack);
- }
- public void SettingsContinueBtn(){
- settingsScreen.SetActive(false);
- }
- public void SettingsMenuBtn(){
- settingsContinue.GetComponent<Button>().interactable = false;
- settingsMenu.GetComponent<Button>().interactable = false;
- PhotonNetwork.AutomaticallySyncScene = false;
- AdsManager.Instance.ShowInterstitialAd();
- if (PhotonNetwork.InRoom){
- PhotonNetwork.LeaveRoom();
- }
- }
- public void Shoot(){
- playerSlider.interactable = false;
- if (opponentSlider != null){
- opponentSlider.interactable = false;
- }
- shootAgain = false;
- gameState = GameState.WAIT;
- playerSlider.value = 0.5f;
- if (opponentSlider != null){
- opponentSlider.value = 0.5f;
- }
- StartCoroutine(WaitForPucks());
- }
- public void NavigatorSliderValueChanged(){
- if (!playerPhotonView.IsMine || gameState != GameState.READY) return;
- playerPuck.transform.localPosition = new Vector2(Mathf.Lerp(playerPuckMinX, playerPuckMaxX, playerSlider.value),playerPuck.transform.localPosition.y);
- }
- bool GetPuckStatus(){
- for (int i = 0; i < allPucks.Length; i++){
- if (allPucks[i].isMoving){
- reduceTimer = false;
- return false;
- }
- }
- if (PlayerPuck.Instance.isMoving){
- return false;
- }
- return true;
- }
- public void CheckTurn(){
- redPuckWaiting = false;
- reduceTimer = true;
- timer = Constants.PLAY_TIME_FOR_PLAYER;
- topHomeAvatarTimer.fillAmount = 0;
- topAwayAvatarTimer.fillAmount = 0;
- if (PhotonNetwork.IsMasterClient){
- PlayerPuck.Instance.ResetPosition();
- playerSlider.interactable = true;
- if (opponentSlider != null){
- opponentSlider.interactable = false;
- }
- } else{
- playerSlider.interactable = false;
- if (opponentSlider != null){
- opponentSlider.interactable = true;
- }
- }
- gameState = GameState.READY;
- if (practiceMode){
- allPucks[0].ResetPosition();
- }
- for (int i = 0; i < allPucks.Length; i++){
- allPucks[i].GetComponent<CircleCollider2D>().enabled = true;
- }
- }
- public void PuckOnHole(string puckTag, string puckName){
- if (practiceMode) return;
- if(gameState == GameState.WIN || gameState == GameState.LOSE) return;
- if (puckTag == "Player"){
- pucksCollected.Add(playerPuck.gameObject);
- } else {
- Puck getPuck = getPuckFromList(puckName);
- if (getPuck != null){
- pucksCollected.Add(getPuck.gameObject);
- }
- }
- }
- Puck getPuckFromList(string puckName){
- for (int i = 0; i < allPucks.Length; i++){
- if (allPucks[i].name == puckName){
- return allPucks[i];
- }
- }
- return null;
- }
- IEnumerator WaitForPucks(){
- yield return new WaitForSecondsRealtime(1f);
- yield return new WaitUntil(() => isPucksFixed);
- yield return new WaitForSecondsRealtime(1f);
- CheckGameStatus();
- }
- void CheckGameStatus(){
- if (pucksCollected.Contains(playerPuck.gameObject)){
- CheckPlayerPenalty();
- } else if (pucksCollected.Contains(redPuck)){
- CheckRedPuckPenalty();
- } else {
- CheckPucks();
- }
- playerPuck.GetComponent<PlayerPuck>().ResetPosition();
- UpdateScoreText();
- if (practiceMode){
- CheckTurn();
- return;
- }
- if (PhotonController.Instance.whichMode == "disc"){
- if (homePucksCollected.Count == 2){
- gameState = targetTag == "White" ? GameState.WIN : GameState.LOSE;
- } else if (awayPucksCollected.Count == 2){
- gameState = targetTag == "Black" ? GameState.WIN : GameState.LOSE;
- }
- } else if (PhotonController.Instance.whichMode == "carrom"){
- if (redPuckCollected){
- if (homePucksCollected.Count == 2){
- gameState = targetTag == "White" ? GameState.WIN : GameState.LOSE;
- } else if (awayPucksCollected.Count == 2){
- gameState = targetTag == "Black" ? GameState.WIN : GameState.LOSE;
- }
- }
- }
- if (gameState == GameState.WIN || gameState == GameState.LOSE){
- GameOver();
- return;
- }
- PlayerPuck.Instance.ResetPosition();
- reduceTimer = true;
- if (gameState == GameState.WAIT && playerPhotonView.IsMine){
- if (!shootAgain){
- gameState = GameState.SWITCH_MASTER;
- StartCoroutine(SwitchMasterDelay());
- } else{
- playerSlider.interactable = true;
- gameState = GameState.READY;
- }
- } else{
- gameState = GameState.READY;
- }
- }
- IEnumerator SwitchMasterDelay(){
- yield return new WaitForSecondsRealtime(1.5f);
- PhotonNetwork.SetMasterClient(PhotonNetwork.MasterClient.GetNext());
- }
- void CheckPlayerPenalty(){
- if (pucksCollected.Contains(redPuck)){
- pucksCollected.Remove(redPuck);
- redPuck.GetComponent<Puck>().ResetPosition();
- }
- for (int i = 0; i < pucksCollected.Count; i++){
- GameObject targetPuck = pucksCollected[i];
- if(targetPuck.CompareTag("Player")) continue;
- if (targetPuck.CompareTag(masterClientTag)){
- targetPuck.GetComponent<Puck>().ResetPosition();
- } else {
- if (masterClientTag == "White"){
- if (awayPucksCollected.Count < 2){
- awayPucksCollected.Add(targetPuck);
- }
- } else {
- if (homePucksCollected.Count < 2){
- homePucksCollected.Add(targetPuck);
- }
- }
- targetPuck.GetComponent<Puck>().ResetPosition();
- }
- }
- pucksCollected.Clear();
- if (masterClientTag == "White"){
- if (homePucksCollected.Count > 0){
- GameObject targetPuck = homePucksCollected[0];
- homePucksCollected.Remove(targetPuck);
- targetPuck.GetComponent<Puck>().ResetPosition();
- }
- } else {
- if (awayPucksCollected.Count > 0){
- GameObject targetPuck = awayPucksCollected[0];
- awayPucksCollected.Remove(targetPuck);
- targetPuck.GetComponent<Puck>().ResetPosition();
- }
- }
- }
- void CheckRedPuckPenalty(){
- if (pucksCollected.Count == 1){
- redPuckWaiting = true;
- shootAgain = true;
- pucksCollected.Remove(redPuck);
- return;
- }
- for (int i = 0; i < pucksCollected.Count; i++){
- GameObject targetPuck = pucksCollected[i];
- if(targetPuck.CompareTag("Player")) continue;
- targetPuck.GetComponent<Puck>().ResetPosition();
- }
- pucksCollected.Clear();
- }
- void CheckPucks(){
- bool tempRedPuckWaiting = redPuckWaiting;
- if (pucksCollected.Count == 0){
- if (redPuckWaiting){
- redPuckWaiting = false;
- redPuck.GetComponent<Puck>().ResetPosition();
- }
- return;
- }
- for (int i = 0; i < pucksCollected.Count; i++){
- var targetPuck = pucksCollected[i];
- if (targetPuck.CompareTag(masterClientTag)){
- shootAgain = true;
- }
- if (PhotonController.Instance.whichMode == "carrom"){
- if (masterClientTag == "White"){
- if (targetPuck.CompareTag("White")){
- if (tempRedPuckWaiting){
- redPuckCollected = true;
- tempRedPuckWaiting = false;
- }
- if (homePucksCollected.Count == 1 && !redPuckCollected){
- targetPuck.GetComponent<Puck>().ResetPosition();
- } else {
- homePucksCollected.Add(targetPuck);
- }
- } else {
- if (tempRedPuckWaiting){
- tempRedPuckWaiting = false;
- redPuck.GetComponent<Puck>().ResetPosition();
- targetPuck.GetComponent<Puck>().ResetPosition();
- } else {
- if (awayPucksCollected.Count == 1){
- if (redPuckCollected){
- awayPucksCollected.Add(targetPuck);
- } else {
- targetPuck.GetComponent<Puck>().ResetPosition();
- }
- } else{
- awayPucksCollected.Add(targetPuck);
- }
- }
- }
- } else if (masterClientTag == "Black"){
- if (targetPuck.CompareTag("Black")){
- if (tempRedPuckWaiting){
- redPuckCollected = true;
- tempRedPuckWaiting = false;
- }
- if (awayPucksCollected.Count == 1 && !redPuckCollected){
- targetPuck.GetComponent<Puck>().ResetPosition();
- } else {
- awayPucksCollected.Add(targetPuck);
- }
- } else {
- if (tempRedPuckWaiting){
- tempRedPuckWaiting = false;
- redPuck.GetComponent<Puck>().ResetPosition();
- targetPuck.GetComponent<Puck>().ResetPosition();
- } else {
- if (homePucksCollected.Count == 1){
- if (redPuckCollected){
- homePucksCollected.Add(targetPuck);
- } else {
- targetPuck.GetComponent<Puck>().ResetPosition();
- }
- } else{
- homePucksCollected.Add(targetPuck);
- }
- }
- }
- }
- } else {
- if (targetPuck.CompareTag("White")){
- homePucksCollected.Add(targetPuck);
- } else if (targetPuck.CompareTag("Black")){
- awayPucksCollected.Add(targetPuck);
- }
- }
- }
- pucksCollected.Clear();
- redPuckWaiting = tempRedPuckWaiting;
- }
- void UpdateScoreText(){
- if (homePucksCollected.Contains(redPuck)){
- topHomeScoreText.text = (homePucksCollected.Count - 1).ToString();
- } else{
- topHomeScoreText.text = homePucksCollected.Count.ToString();
- }
- if (awayPucksCollected.Contains(redPuck)){
- topAwayScoreText.text = (awayPucksCollected.Count - 1).ToString();
- } else {
- topAwayScoreText.text = awayPucksCollected.Count.ToString();
- }
- }
- public void CheckRoomPlayers(){
- if (gameState == GameState.WIN || gameState == GameState.LOSE) return;
- if (PhotonNetwork.PlayerList.Length == 1){
- gameState = GameState.WIN;
- GameOver();
- }
- }
- void GameOver(){
- settingsScreen.SetActive(false);
- PhotonNetwork.AutomaticallySyncScene = false;
- if (gameState == GameState.WIN){
- PlayerPrefs.SetInt("coin", PlayerPrefs.GetInt("coin") + (PhotonController.Instance.roomEntryPice * 2));
- PlayerPrefs.Save();
- statusPanelText.text = "YOU WIN";
- } else if (gameState == GameState.LOSE){
- statusPanelText.text = "YOU LOSE";
- }
- statusPanel.anchoredPosition = new Vector2(-940f, statusPanel.anchoredPosition.y);
- statusBackground.color = new Color(0, 0, 0, 0);
- statusScreen.SetActive(true);
- LeanTween.alpha(statusBackground.GetComponent<RectTransform>(), 0.75f, 0.5f);
- LeanTween.move(statusPanel, new Vector2(0, statusPanel.anchoredPosition.y), 0.3f).setDelay(0.5f)
- .setEase(LeanTweenType.easeOutBack).setOnComplete(() => {
- LeanTween.move(statusPanel, new Vector2(940, statusPanel.anchoredPosition.y), 0.3f).setDelay(1f)
- .setEase(LeanTweenType.easeInBack).setOnComplete(
- () => {
- statusBackground.color = new Color(0, 0, 0, 0);
- Vector2 targetPos = topCoinParentForAnim.position;
- if (gameState == GameState.WIN){
- if (targetTag == "White"){
- targetPos = topHomeAvatarTimer.transform.position;
- } else{
- targetPos = topAwayAvatarTimer.transform.position;
- }
- } else if (gameState == GameState.LOSE){
- if (targetTag == "White"){
- targetPos = topAwayAvatarTimer.transform.position;
- } else{
- targetPos = topHomeAvatarTimer.transform.position;
- }
- }
- topCoinParentForAnim.gameObject.SetActive(true);
- for (int i = 0; i < topCoinParentForAnim.childCount; i++){
- GameObject go = topCoinParentForAnim.GetChild(i).gameObject;
- LeanTween.move(go, targetPos, 0.5f).setDelay(i * 0.1f).setOnComplete(() => {
- go.SetActive(false);
- });
- }
- LeanTween.value(PhotonController.Instance.roomEntryPice * 2, 0, 1.5f).setOnUpdate(
- (float val) => {
- if (val < 1){
- topTotalBetText.text = "0";
- } else{
- topTotalBetText.text = ((int)val).ToString("###,###,###");
- }
- }).setOnComplete(() => {
- AdsManager.Instance.ShowInterstitialAd();
- if (PhotonNetwork.InRoom){
- PhotonNetwork.LeaveRoom();
- }
- });
- });
- });
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using Photon.Pun;
- using Photon.Realtime;
- namespace BEKStudio{
- public class PhotonController : MonoBehaviourPunCallbacks {
- public static PhotonController Instance;
- public string whichMode;
- public string whichRoom;
- public int roomEntryPice = 0;
- void Awake() {
- if (Instance == null) {
- Instance = this;
- }
- }
- public void Start() {
- PhotonNetwork.KeepAliveInBackground = 60;
- if (!PhotonNetwork.IsConnectedAndReady) {
- PhotonNetwork.ConnectUsingSettings();
- } else {
- JoinLobby();
- }
- }
- public override void OnConnectedToMaster() {
- if (PlayerPrefs.HasKey("username")){
- PhotonNetwork.NickName = PlayerPrefs.GetString("username");
- }
- JoinLobby();
- }
- public void JoinLobby() {
- PhotonNetwork.JoinLobby();
- }
- public override void OnJoinedLobby(){
- }
- public override void OnLeftLobby(){
- }
- public void FindRoom() {
- MenuController.Instance.vsMsgText.text = "Searching room...";
- ExitGames.Client.Photon.Hashtable roomHastable = new ExitGames.Client.Photon.Hashtable {
- { "roomType", whichRoom }
- };
- PhotonNetwork.JoinRandomRoom(roomHastable, 0);
- }
- public void CreatePracticeRoom(){
- RoomOptions roomOptions = new RoomOptions();
- roomOptions.CustomRoomPropertiesForLobby = new string[] { "roomType" };
- roomOptions.IsOpen = false;
- roomOptions.IsVisible = false;
- PhotonNetwork.CreateRoom(null, roomOptions);
- }
- public override void OnJoinRandomFailed(short returnCode, string message) {
- ExitGames.Client.Photon.Hashtable roomHastable = new ExitGames.Client.Photon.Hashtable {
- { "roomType", whichRoom }
- };
- RoomOptions roomOptions = new RoomOptions();
- roomOptions.CustomRoomProperties = roomHastable;
- roomOptions.CustomRoomPropertiesForLobby = new string[] { "roomType" };
- roomOptions.IsOpen = true;
- roomOptions.IsVisible = true;
- PhotonNetwork.CreateRoom(null, roomOptions);
- }
- public override void OnJoinedRoom() {
- if (whichMode == "practice"){
- SceneManager.LoadScene("Practice");
- } else{
- ExitGames.Client.Photon.Hashtable userHastable = new ExitGames.Client.Photon.Hashtable();
- userHastable.Add("avatar", PlayerPrefs.GetInt("avatar"));
- if (PhotonNetwork.PlayerList.Length == 1){
- userHastable.Add("tag", "White");
- } else {
- userHastable.Add("tag", "Black");
- }
- PhotonNetwork.LocalPlayer.SetCustomProperties(userHastable);
- MenuController.Instance.VsJoinedRoom();
- PhotonNetwork.AutomaticallySyncScene = true;
- }
- }
- public override void OnLeftRoom() {
- PhotonNetwork.AutomaticallySyncScene = false;
- if (SceneManager.GetActiveScene().name == "Menu") {
- MenuController.Instance.VsOnLeftRoom();
- } else if (SceneManager.GetActiveScene().name == "Game" || SceneManager.GetActiveScene().name == "Practice"){
- SceneManager.LoadScene("Menu");
- }
- }
- public override void OnCreatedRoom() {
- }
- public override void OnPlayerEnteredRoom(Player newPlayer) {
- if (PhotonNetwork.IsMasterClient) {
- MenuController.Instance.VsOnPlayerJoinedRoom();
- }
- }
- public override void OnPlayerLeftRoom(Player otherPlayer) {
- if (SceneManager.GetActiveScene().name == "Game") {
- GameController.Instance.CheckRoomPlayers();
- }
- }
- public override void OnMasterClientSwitched(Player newMasterClient){
- GameController.Instance.masterClientTag = (string)newMasterClient.CustomProperties["tag"];
- GameController.Instance.CheckTurn();
- }
- public override void OnDisconnected(DisconnectCause cause) {
- }
- }
- }
- using UnityEngine;
- using TMPro;
- using Photon.Pun;
- using Photon.Realtime;
- using ExitGames.Client.Photon;
- using System.Collections;
- using Hashtable = ExitGames.Client.Photon.Hashtable;
- namespace BEKStudio
- {
- public class RoomManager : MonoBehaviourPunCallbacks
- {
- [Header("Panels")]
- public GameObject roomMenuPanel; // Панель с кнопками "Создать" и "Войти"
- public GameObject createRoomPanel; // Панель создания комнаты
- public GameObject joinRoomPanel; // Панель входа в комнату
- [Header("Create Room Fields")]
- public TMP_InputField roomNameInput; // Поле для ввода имени комнаты
- public TMP_InputField roomPasswordInput; // Поле для ввода пароля для комнаты
- public TMP_InputField roomCoinBetInput; // Поле для ввода ставки в монетах
- [Header("Join Room Fields")]
- public TMP_InputField joinRoomNameInput; // Поле для ввода имени комнаты при присоединении
- public TMP_InputField joinRoomPasswordInput; // Поле для ввода пароля при присоединении
- private string inputPassword; // Временное хранение введенного пароля
- private bool isJoiningRoom = false; // Флаг, чтобы различать создание и вход
- void Start()
- {
- roomMenuPanel.SetActive(true); // Показываем главное меню при запуске
- createRoomPanel.SetActive(false); // Скрываем панель создания комнаты
- joinRoomPanel.SetActive(false); // Скрываем панель входа в комнату
- }
- // Открыть панель для создания комнаты
- public void OpenCreateRoomPanel()
- {
- roomMenuPanel.SetActive(false); // Скрываем главное меню
- createRoomPanel.SetActive(true); // Показываем панель для создания комнаты
- }
- // Открыть панель для входа в комнату
- public void OpenJoinRoomPanel()
- {
- roomMenuPanel.SetActive(false); // Скрываем главное меню
- joinRoomPanel.SetActive(true); // Показываем панель для входа в комнату
- }
- // Вернуться в главное меню
- public void BackToMenu()
- {
- createRoomPanel.SetActive(false); // Скрываем панель для создания комнаты
- joinRoomPanel.SetActive(false); // Скрываем панель для входа в комнату
- roomMenuPanel.SetActive(true); // Показываем главное меню
- }
- // Создание комнаты с кастомными параметрами
- public void CreateRoom()
- {
- string roomName = roomNameInput.text; // Получаем имя комнаты
- string password = roomPasswordInput.text; // Получаем пароль для комнаты
- string coinBet = roomCoinBetInput.text; // Получаем ставку в монетах
- // Создаем хэш-таблицу для хранения кастомных свойств комнаты
- Hashtable roomProperties = new Hashtable
- {
- { "password", password }, // Добавляем пароль в свойства комнаты
- { "coinBet", coinBet } // Добавляем ставку в монетах
- };
- // Создаем опции для комнаты
- RoomOptions options = new RoomOptions
- {
- MaxPlayers = 2, // Максимальное количество игроков в комнате
- CustomRoomProperties = roomProperties, // Устанавливаем кастомные свойства
- CustomRoomPropertiesForLobby = new string[] { "coinBet" } // Добавляем ставки в монетах в список свойств для лобби
- };
- // Создаем комнату с заданными параметрами
- PhotonNetwork.CreateRoom(roomName, options, TypedLobby.Default);
- Debug.Log($"Комната создана: {roomName}, пароль: {password}, ставка: {coinBet}");
- }
- // Вход в комнату с проверкой пароля
- public void JoinRoom()
- {
- string roomName = joinRoomNameInput.text; // Получаем имя комнаты
- inputPassword = joinRoomPasswordInput.text; // Сохраняем введенный пароль
- isJoiningRoom = true; // Устанавливаем флаг входа
- PhotonNetwork.JoinRoom(roomName); // Пробуем присоединиться к комнате
- }
- // Вызывается после успешного входа в комнату
- public override void OnJoinedRoom()
- {
- if (isJoiningRoom) // Проверяем пароль только при входе, не при создании
- {
- string roomPassword = PhotonNetwork.CurrentRoom.CustomProperties["password"].ToString(); // Получаем пароль из свойств комнаты
- if (roomPassword == inputPassword) // Если пароль правильный
- {
- Debug.Log("Пароль верный. Подключение успешно!");
- }
- else // Если пароль неверный
- {
- Debug.LogError("Неверный пароль. Отключаемся...");
- PhotonNetwork.LeaveRoom(); // Отключаемся от комнаты
- }
- }
- else
- {
- Debug.Log("Комната успешно создана.");
- }
- isJoiningRoom = false; // Сбрасываем флаг
- }
- // Обработчик ошибки при создании комнаты
- public override void OnCreateRoomFailed(short returnCode, string message)
- {
- Debug.LogError("Ошибка создания комнаты: " + message);
- }
- // Обработчик ошибки при входе в комнату
- public override void OnJoinRoomFailed(short returnCode, string message)
- {
- Debug.LogError("Ошибка подключения к комнате: " + message);
- isJoiningRoom = false; // Сбрасываем флаг
- }
- // Обработчик, когда игрок покидает комнату
- public override void OnLeftRoom()
- {
- Debug.Log("Отключен от комнаты.");
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using BEKStudio;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using TMPro;
- using Photon.Realtime;
- using Photon.Pun;
- using Hashtable = ExitGames.Client.Photon.Hashtable;
- namespace BEKStudio{
- public class MenuController : MonoBehaviour{
- public static MenuController Instance;
- public GameObject dontDestroyPrefab;
- public TextMeshProUGUI coinText;
- public Image avatarImg;
- public TextMeshProUGUI avatarUsernameText;
- public Sprite[] avatars;
- [Header("Main")] public GameObject mainScreen;
- public RectTransform mainDiscPoolRect;
- public RectTransform mainCarromRect;
- public RectTransform mainPracticeRect;
- [Header("Room")] public GameObject roomScreen;
- public TextMeshProUGUI roomLondonEntryPriceText;
- public TextMeshProUGUI roomLondonWinPriceText;
- public TextMeshProUGUI roomParisEntryPriceText;
- public TextMeshProUGUI roomParisWinPriceText;
- public TextMeshProUGUI roomBerlinEntryPriceText;
- public TextMeshProUGUI roomBerlinWinPriceText;
- [Header("Vs")] public GameObject vsScreen;
- public TextMeshProUGUI vsMsgText;
- public Button vsBackBtn;
- public GameObject vsUsersParent;
- public TextMeshProUGUI vsHomeUsernameText;
- public TextMeshProUGUI vsHomeUserBetText;
- public TextMeshProUGUI vsAwayUsernameText;
- public TextMeshProUGUI vsAwayUserBetText;
- public TextMeshProUGUI vsTotalBetText;
- [Header("Username")] public GameObject usernameScreen;
- public TMP_InputField usernameText;
- [Header("Shop")] public GameObject shopScreen;
- void Awake(){
- if (Instance == null){
- Instance = this;
- }
- }
- void Start(){
- if (!PlayerPrefs.HasKey("default")){
- PlayerPrefs.SetInt("default", 1);
- PlayerPrefs.SetInt("avatar", Random.Range(0, 20));
- PlayerPrefs.SetInt("coin", Constants.DEFAULT_COIN);
- PlayerPrefs.Save();
- }
- avatarImg.sprite = avatars[PlayerPrefs.GetInt("avatar")];
- GameObject dontDestroyObj = GameObject.Find("DontDestroy");
- if (dontDestroyObj == null){
- dontDestroyObj = Instantiate(dontDestroyPrefab);
- dontDestroyObj.name = "DontDestroy";
- DontDestroyOnLoad(dontDestroyObj);
- }
- UpdateCurrencyText();
- mainScreen.SetActive(false);
- roomScreen.SetActive(false);
- vsScreen.SetActive(false);
- shopScreen.SetActive(false);
- usernameScreen.SetActive(false);
- if (PlayerPrefs.HasKey("username")){
- avatarUsernameText.text = PlayerPrefs.GetString("username");
- OpenMainScreen();
- } else {
- usernameScreen.SetActive(true);
- }
- Hashtable playerProperties = new Hashtable{
- { "avatar", PlayerPrefs.GetInt("avatar") }
- };
- PhotonNetwork.SetPlayerCustomProperties(playerProperties);
- }
- public void UsernameSaveBtn(){
- if (usernameText.text.Length < 3) return;
- PlayerPrefs.SetString("username", usernameText.text);
- PlayerPrefs.Save();
- if (PhotonNetwork.IsConnectedAndReady){
- PhotonNetwork.NickName = usernameText.text;
- }
- avatarUsernameText.text = PlayerPrefs.GetString("username");
- OpenMainScreen();
- }
- void OpenMainScreen(){
- mainScreen.SetActive(true);
- roomScreen.SetActive(false);
- vsScreen.SetActive(false);
- shopScreen.SetActive(false);
- usernameScreen.SetActive(false);
- mainDiscPoolRect.anchoredPosition = new Vector2(-759f, -198f);
- mainCarromRect.anchoredPosition = new Vector2(759f, -198f);
- mainPracticeRect.anchoredPosition = new Vector2(0, -1103);
- LeanTween.move(mainDiscPoolRect, new Vector2(-216f, -198f), 0.5f).setEaseOutBack();
- LeanTween.move(mainCarromRect, new Vector2(227, -198f), 0.5f).setEaseOutBack();
- LeanTween.move(mainPracticeRect, new Vector2(0, -744), 0.5f).setEaseOutBack();
- }
- public void UpdateCurrencyText(){
- if (PlayerPrefs.GetInt("coin") == 0){
- coinText.text = "0";
- }
- else{
- coinText.text = PlayerPrefs.GetInt("coin", 0).ToString("###,###,###");
- }
- }
- public void FreeCoinsBtn(){
- AdsManager.Instance.ShowRewardedAd();
- }
- public void DiscPoolBtn(){
- if(!PhotonNetwork.IsConnectedAndReady) return;
- if (PlayerPrefs.GetInt("coin") == 0){
- ShopBtn();
- return;
- }
- PhotonController.Instance.whichMode = "disc";
- ShowRooms();
- }
- public void CarromBtn(){
- if(!PhotonNetwork.IsConnectedAndReady) return;
- if (PlayerPrefs.GetInt("coin") == 0){
- ShopBtn();
- return;
- }
- PhotonController.Instance.whichMode = "carrom";
- ShowRooms();
- }
- public void PracticeModeBtn(){
- if(!PhotonNetwork.IsConnectedAndReady) return;
- PhotonController.Instance.whichMode = "practice";
- PhotonController.Instance.CreatePracticeRoom();
- }
- public void ShopBtn(){
- if (shopScreen.activeInHierarchy) return;
- mainScreen.SetActive(false);
- shopScreen.SetActive(true);
- }
- public void ShopItemBtn(int id){
- Purchaser.Instance.BuyConsumable(id);
- }
- public void ShopBackBtn(){
- mainScreen.SetActive(true);
- shopScreen.SetActive(false);
- }
- public void ShowRooms(){
- roomLondonEntryPriceText.text = Constants.ROOM_LONDON_ENTRY_PRICE.ToString("###,###,###");
- roomLondonWinPriceText.text = (Constants.ROOM_LONDON_ENTRY_PRICE * 2).ToString("###,###,###");
- roomParisEntryPriceText.text = Constants.ROOM_PARIS_ENTRY_PRICE.ToString("###,###,###");
- roomParisWinPriceText.text = (Constants.ROOM_PARIS_ENTRY_PRICE * 2).ToString("###,###,###");
- roomBerlinEntryPriceText.text = Constants.ROOM_BERLIN_ENTRY_PRICE.ToString("###,###,###");
- roomBerlinWinPriceText.text = (Constants.ROOM_BERLIN_ENTRY_PRICE * 2).ToString("###,###,###");
- mainScreen.SetActive(false);
- roomScreen.SetActive(true);
- }
- public void RoomsBtn(string room){
- roomScreen.SetActive(false);
- vsBackBtn.gameObject.SetActive(false);
- vsBackBtn.interactable = true;
- vsUsersParent.SetActive(false);
- vsScreen.SetActive(true);
- PhotonController.Instance.whichRoom = room;
- if (room == "london"){
- PhotonController.Instance.roomEntryPice = Constants.ROOM_LONDON_ENTRY_PRICE;
- }
- else if (room == "paris"){
- PhotonController.Instance.roomEntryPice = Constants.ROOM_PARIS_ENTRY_PRICE;
- }
- else if (room == "berlin"){
- PhotonController.Instance.roomEntryPice = Constants.ROOM_BERLIN_ENTRY_PRICE;
- }
- PhotonController.Instance.FindRoom();
- }
- public void RoomsBackBtn(){
- mainScreen.SetActive(true);
- roomScreen.SetActive(false);
- }
- public void VsBackBtn(){
- vsBackBtn.interactable = false;
- vsMsgText.text = "Leaveing room...";
- PhotonNetwork.LeaveRoom();
- }
- public void VsOnLeftRoom(){
- vsBackBtn.gameObject.SetActive(false);
- vsBackBtn.interactable = true;
- vsUsersParent.SetActive(false);
- vsScreen.SetActive(false);
- mainScreen.SetActive(true);
- }
- public void VsJoinedRoom(){
- vsHomeUserBetText.text = PhotonController.Instance.roomEntryPice.ToString("###,###,###");
- vsAwayUserBetText.text = PhotonController.Instance.roomEntryPice.ToString("###,###,###");
- vsTotalBetText.text = "0";
- vsBackBtn.gameObject.SetActive(true);
- vsBackBtn.interactable = true;
- vsMsgText.text = "Waiting opponent...";
- vsUsersParent.SetActive(true);
- if (PhotonNetwork.PlayerList.Length == 1){
- vsHomeUsernameText.text = PhotonNetwork.PlayerList[0].NickName;
- }
- else if (PhotonNetwork.PlayerList.Length == 2){
- vsHomeUsernameText.text = PhotonNetwork.PlayerList[0].NickName;
- vsAwayUsernameText.text = PhotonNetwork.PlayerList[1].NickName;
- VsStartMatch();
- }
- }
- public void VsOnPlayerJoinedRoom(){
- if (PhotonNetwork.CurrentRoom.PlayerCount == 2){
- PhotonNetwork.CurrentRoom.IsOpen = false;
- PhotonNetwork.CurrentRoom.IsVisible = false;
- vsHomeUsernameText.text = PhotonNetwork.PlayerList[0].NickName;
- vsAwayUsernameText.text = PhotonNetwork.PlayerList[1].NickName;
- VsStartMatch();
- }
- }
- void VsStartMatch(){
- float currentCoin = PlayerPrefs.GetInt("coin");
- float newCoin = currentCoin - PhotonController.Instance.roomEntryPice;
- PlayerPrefs.SetInt("coin", PlayerPrefs.GetInt("coin") - PhotonController.Instance.roomEntryPice);
- PlayerPrefs.Save();
- vsBackBtn.gameObject.SetActive(false);
- LeanTween.value(PhotonController.Instance.roomEntryPice, 0, 1f).setOnUpdate((float val) => {
- vsHomeUserBetText.text = "" + (int)val;
- vsAwayUserBetText.text = "" + (int)val;
- });
- LeanTween.value(currentCoin, newCoin, 1f).setOnUpdate((float val) => {
- if (val < 1){
- coinText.text = "0";
- }
- else{
- coinText.text = ((int)val).ToString("###,###,###");
- }
- });
- LeanTween.value(0, PhotonController.Instance.roomEntryPice * 2, 1f).setOnUpdate((float val) => {
- vsTotalBetText.text = "" + (int)val;
- }).setOnComplete(() => {
- UpdateCurrencyText();
- if (PhotonNetwork.IsMasterClient){
- SceneManager.LoadScene("Game");
- }
- });
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace BEKStudio{
- public class Constants{
- public static int DEFAULT_COIN = 1000;
- public static float PLAY_TIME_FOR_PLAYER = 15;
- public static int ROOM_LONDON_ENTRY_PRICE = 250;
- public static int ROOM_PARIS_ENTRY_PRICE = 500;
- public static int ROOM_BERLIN_ENTRY_PRICE = 1000;
- public static string ADMOB_INTERSTITIAL_ANDROID_ID = "ca-app-pub-3940256099942544/1033173712";
- public static string ADMOB_INTERSTITIAL_IOS_ID = "ca-app-pub-3940256099942544/4411468910";
- public static string ADMOB_REWARDED_ANDROID_ID = "ca-app-pub-3940256099942544/5224354917";
- public static string ADMOB_REWARDED_IOS_ID = "ca-app-pub-3940256099942544/1712485313";
- public static int REWARDED_AD_PRIZE = 250;
- public static string SHOP_PACK_1_ID = "coin5000";
- public static string SHOP_PACK_2_ID = "coin10000";
- public static string SHOP_PACK_3_ID = "coin25000";
- public static string SHOP_PACK_4_ID = "coin50000";
- public static int SHOP_PACK_1_COIN = 5000;
- public static int SHOP_PACK_2_COIN = 10000;
- public static int SHOP_PACK_3_COIN = 25000;
- public static int SHOP_PACK_4_COIN = 50000;
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Photon.Pun;
- using BEKStudio;
- namespace BEKStudio{
- public class PlayerPuck : MonoBehaviourPun, IPunObservable{
- public static PlayerPuck Instance;
- Rigidbody2D rb;
- SpriteRenderer spriteRenderer;
- PhotonView photonView;
- public PhysicsMaterial2D physicMaterial;
- public Vector2 startPos;
- public Vector2 endPos;
- public Vector2 totalPos;
- public bool isTouch;
- float opponentSliderValue;
- Vector2 puckStartPos;
- public GameObject arrow;
- public float force;
- float forceMultiplier;
- Vector2 lastVel;
- public bool isMoving;
- private Vector2 arrowLocalScale;
- public GameObject tutorial;
- public float tutorialShowDelay = 2;
- void Awake(){
- if (Instance == null){
- Instance = this;
- }
- }
- void Start(){
- rb = GetComponent<Rigidbody2D>();
- spriteRenderer = GetComponent<SpriteRenderer>();
- photonView = GetComponent<PhotonView>();
- puckStartPos = transform.localPosition;
- opponentSliderValue = 0.5f;
- lastVel = Vector2.zero;
- isMoving = false;
- arrowLocalScale = arrow.transform.localScale;
- }
- void Update(){
- isMoving = lastVel != Vector2.zero;
- if (GameController.Instance.opponentSlider != null){
- GameController.Instance.opponentSlider.value = Mathf.MoveTowards(
- GameController.Instance.opponentSlider.value, opponentSliderValue, 5 * Time.deltaTime);
- }
- if (photonView.IsMine){
- opponentSliderValue = 0.5f;
- if (rb.sharedMaterial == null){
- rb.sharedMaterial = physicMaterial;
- }
- if (arrow.activeInHierarchy){
- arrow.transform.localScale =
- Vector2.MoveTowards(arrow.transform.localScale, arrowLocalScale, 5 * Time.deltaTime);
- }
- if (!isTouch && GameController.Instance.gameState == GameController.GameState.READY){
- if (tutorialShowDelay > 0){
- tutorialShowDelay -= 1 * Time.deltaTime;
- }
- else{
- if (!tutorial.activeInHierarchy){
- tutorial.SetActive(true);
- }
- }
- }
- }
- else{
- tutorial.SetActive(false);
- if (rb.sharedMaterial != null){
- rb.sharedMaterial = null;
- }
- if (arrow.activeInHierarchy){
- arrow.transform.localScale = Vector2.MoveTowards(arrow.transform.localScale, arrowLocalScale,
- 50 * Time.deltaTime);
- }
- return;
- }
- if (isTouch){
- endPos = Input.mousePosition;
- totalPos = endPos - startPos;
- forceMultiplier = Mathf.InverseLerp(0, 500, (endPos - startPos).magnitude);
- if (forceMultiplier >= 0.2f){
- arrow.GetComponent<SpriteRenderer>().enabled = true;
- }
- else{
- arrow.GetComponent<SpriteRenderer>().enabled = false;
- }
- arrow.transform.localScale = new Vector3(forceMultiplier * 2.3f, forceMultiplier * 2.3f, 1);
- float AngleRad = Mathf.Atan2(-(endPos.y - startPos.y), -(endPos.x - startPos.x));
- float AngleDeg = (180 / Mathf.PI) * AngleRad;
- transform.rotation = Quaternion.Euler(0, 0, AngleDeg);
- }
- }
- void FixedUpdate(){
- if (photonView.IsMine){
- lastVel = rb.linearVelocity;
- }
- }
- public void OnMouseDown(){
- if (!photonView.IsMine || GameController.Instance.gameState != GameController.GameState.READY) return;
- arrow.transform.localScale = Vector2.zero;
- arrow.SetActive(true);
- startPos = Input.mousePosition;
- endPos = startPos;
- isTouch = true;
- tutorial.SetActive(false);
- tutorialShowDelay = 2;
- }
- public void OnMouseUp(){
- if (!photonView.IsMine || GameController.Instance.gameState != GameController.GameState.READY) return;
- arrow.SetActive(false);
- isTouch = false;
- if (forceMultiplier >= 0.2f){
- photonView.RPC("Shoot", RpcTarget.AllBuffered);
- }
- }
- [PunRPC]
- void Shoot(){
- if (photonView.IsMine){
- rb.AddForce(transform.right * (forceMultiplier * force), ForceMode2D.Impulse);
- }
- GameController.Instance.Shoot();
- }
- public void ResetPosition(){
- transform.rotation = Quaternion.Euler(0, 0, 90);
- if (photonView.IsMine){
- transform.localPosition = puckStartPos;
- }
- GetComponent<CircleCollider2D>().enabled = true;
- rb.linearVelocity = Vector2.zero;
- rb.simulated = true;
- spriteRenderer.color = new Color32(255, 255, 255, 255);
- lastVel = Vector2.zero;
- isMoving = false;
- }
- public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
- if (stream.IsWriting){
- stream.SendNext(rb.linearVelocity);
- stream.SendNext(GameController.Instance.playerSlider.value);
- stream.SendNext(arrow.activeInHierarchy);
- stream.SendNext(arrow.transform.localScale);
- stream.SendNext(arrow.transform.localRotation);
- }
- else{
- lastVel = (Vector2)stream.ReceiveNext();
- opponentSliderValue = (float)stream.ReceiveNext();
- arrow.SetActive((bool)stream.ReceiveNext());
- arrowLocalScale = (Vector3)stream.ReceiveNext();
- arrow.transform.localRotation = (Quaternion)stream.ReceiveNext();
- }
- }
- void OnTriggerEnter2D(Collider2D col){
- if (col.CompareTag("Hole")){
- GetComponent<CircleCollider2D>().enabled = false;
- rb.linearVelocity = Vector2.zero;
- rb.simulated = false;
- lastVel = Vector2.zero;
- isMoving = false;
- LeanTween.color(gameObject, new Color32(255, 255, 255, 0), 0.5f).setOnComplete(() => {
- if (!photonView.IsMine) return;
- photonView.RPC("PuckOnHole", RpcTarget.AllBuffered, gameObject.tag, gameObject.name);
- });
- }
- }
- [PunRPC]
- void PuckOnHole(string puckTag, string puckName){
- GameController.Instance.PuckOnHole(puckTag, puckName);
- }
- }
- }
- using Photon.Pun;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace BEKStudio{
- public class Puck : MonoBehaviourPun, IPunObservable{
- public PhotonView photonView;
- Rigidbody2D rb;
- SpriteRenderer spriteRenderer;
- Vector2 puckStartPos;
- Vector2 lastVel;
- public bool isMoving;
- void Start(){
- photonView = GetComponent<PhotonView>();
- rb = GetComponent<Rigidbody2D>();
- spriteRenderer = GetComponent<SpriteRenderer>();
- puckStartPos = transform.localPosition;
- lastVel = Vector2.zero;
- isMoving = false;
- if (GameController.Instance.practiceMode){
- ResetPosition();
- }
- }
- void Update(){
- isMoving = lastVel != Vector2.zero;
- }
- void FixedUpdate(){
- if (photonView.IsMine){
- lastVel = rb.linearVelocity;
- }
- }
- public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
- if (stream.IsWriting){
- stream.SendNext(rb.linearVelocity);
- }
- else{
- lastVel = (Vector2)stream.ReceiveNext();
- }
- }
- void OnTriggerEnter2D(Collider2D col){
- if (col.CompareTag("Hole")){
- GetComponent<CircleCollider2D>().enabled = false;
- rb.linearVelocity = Vector2.zero;
- rb.simulated = false;
- lastVel = Vector2.zero;
- isMoving = false;
- LeanTween.color(gameObject, new Color32(255, 255, 255, 0), 0.5f);
- if (!photonView.IsMine) return;
- GetComponent<PhotonView>().RPC("PuckOnHole", RpcTarget.AllBuffered, gameObject.tag, gameObject.name);
- }
- }
- public void ResetPosition(){
- if (GameController.Instance.practiceMode){
- transform.localPosition = new Vector2(Random.Range(-1.89f, 1.89f), Random.Range(-1.16f, 1.16f));
- } else {
- if (photonView.IsMine){
- transform.localPosition = puckStartPos;
- }
- }
- rb.linearVelocity = Vector2.zero;
- rb.simulated = true;
- spriteRenderer.color = new Color32(255, 255, 255, 255);
- lastVel = Vector2.zero;
- isMoving = false;
- }
- [PunRPC]
- void PuckOnHole(string puckTag, string puckName){
- GameController.Instance.PuckOnHole(puckTag, puckName);
- }
- void OnCollisionEnter2D(Collision2D col){
- if (col.gameObject.CompareTag("Player")){
- if (!GetComponent<AudioSource>().isPlaying){
- GetComponent<AudioSource>().Play();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement