From b345dfc48b90005219ad7fdbbcc2ca5b97e1a4d7 Mon Sep 17 00:00:00 2001 From: "sewmina7@gmail.com" Date: Thu, 11 Apr 2024 23:08:55 +0530 Subject: [PATCH] Server fixes and attack anim --- Assets/Script/PlayerAttack.cs | 28 ++++++++++++++++------------ Assets/Script/gplayAuth.cs | 7 +++++-- Assets/Script/playerNetwork.cs | 19 ++++++++++++++++--- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Assets/Script/PlayerAttack.cs b/Assets/Script/PlayerAttack.cs index 8a89dd69..8c2263cb 100644 --- a/Assets/Script/PlayerAttack.cs +++ b/Assets/Script/PlayerAttack.cs @@ -17,29 +17,33 @@ public class PlayerAttack : NetworkBehaviour{ public GameObject leftAnim,rightAnim,upAnim,downAnim; + void Awake(){ + pnet.playerAttack = this; + } + void Start(){ if(!isLocalPlayer){ Destroy(this); } } - void Update(){ - //Get player look dir - if(timeBetweenAttacks <=0){ - if(Input.GetMouseButtonDown(0)){ - StartCoroutine(couroutineAttack()); - timeBetweenAttacks = startTimeBtwAttacks; - } - }else{ - timeBetweenAttacks -= Time.deltaTime; - } - } + // void Update(){ + // //Get player look dir + // if(timeBetweenAttacks <=0){ + // if(Input.GetMouseButtonDown(0)){ + // StartCoroutine(couroutineAttack()); + // timeBetweenAttacks = startTimeBtwAttacks; + // } + // }else{ + // timeBetweenAttacks -= Time.deltaTime; + // } + // } IEnumerator couroutineAttack(){ yield return new WaitForSecondsRealtime(0.6f); Attack(); } - void Attack(){ + public void Attack(){ Vector3 direction = GetPlayerLookDir(); diff --git a/Assets/Script/gplayAuth.cs b/Assets/Script/gplayAuth.cs index e3bcd74f..56e84055 100644 --- a/Assets/Script/gplayAuth.cs +++ b/Assets/Script/gplayAuth.cs @@ -25,8 +25,10 @@ public class gplayAuth : MonoBehaviour{ public TMP_InputField saveName, coins, item1, item2, item3 ; public TMP_Text saveStatText; - public TMP_Text saveNameTxt , coinsTxt, item1Txt, item2Txt, item3Txt; + public static string userNameCloud; + public TMP_Text saveNameTxt , coinsTxt, item1Txt, item2Txt, item3Txt; + #if UNITY_ANDROID void Start() { IsConnected =false; PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestServerAuthCode(false) @@ -37,7 +39,6 @@ public class gplayAuth : MonoBehaviour{ //GPGSLogin(); } - public static string userNameCloud; public void GPGSLogin(){ PlayGamesPlatform.Instance.Authenticate((success) => { @@ -241,4 +242,6 @@ public class gplayAuth : MonoBehaviour{ //load game scene SceneManager.LoadScene("MenuScene"); } + + #endif } diff --git a/Assets/Script/playerNetwork.cs b/Assets/Script/playerNetwork.cs index c13ab426..1434b81c 100644 --- a/Assets/Script/playerNetwork.cs +++ b/Assets/Script/playerNetwork.cs @@ -16,6 +16,8 @@ using UnityEngine.UI; public class playerNetwork : NetworkBehaviour { + public const float ATTACK_COOLDOWN = 0.6f; + //public const int XPFORLEVEL = 10; [SyncVar(hook =nameof(OnHealthChanged))] public int health = 100; public Character4D character; @@ -297,9 +299,14 @@ public class playerNetwork : NetworkBehaviour character.AnimationManager.SetState((CharacterState)newVal); } - + float attackTimer = 0; + [HideInInspector] + public PlayerAttack playerAttack; void Update(){ if(isLocalPlayer){ + + if(attackTimer >0){attackTimer-=Time.deltaTime;} + if(isServer){ SetAnimationData(character.Direction, character.Animator.GetInteger("State")); }else{ @@ -520,8 +527,14 @@ public class playerNetwork : NetworkBehaviour } public void OnAttack(){ + if(attackTimer > 0){ + return; + } + + attackTimer = ATTACK_COOLDOWN; if(isLocalPlayer){ PlayAttackAnim(); + playerAttack.Attack(); if(isServer){ RpcPlayAttackAnim(); }else{ @@ -543,7 +556,7 @@ public class playerNetwork : NetworkBehaviour } void PlayAttackAnim(){ - switch (character.WeaponType) + switch (character.WeaponType) { case WeaponType.Melee1H: case WeaponType.Paired: @@ -607,7 +620,7 @@ public class playerNetwork : NetworkBehaviour startClient.instance.networkManager.StopClient(); SceneManager.LoadScene("GameLogin"); - PlayGamesPlatform.Instance.SignOut(); + // PlayGamesPlatform.Instance.SignOut(); Firebase.Auth.FirebaseAuth.DefaultInstance.SignOut(); }