Better Coin Animation

This commit is contained in:
brausjonas
2023-02-05 22:07:41 +01:00
parent b0ddf261f4
commit 2abea8e99e
45 changed files with 1259 additions and 355 deletions
+16 -4
View File
@@ -24,8 +24,7 @@ public class Client : MonoBehaviour
[SerializeField] private TMP_Text[] playerNameTexts;
[SerializeField] private GameObject[] playerInfo;
[SerializeField] private TMP_Text fpsText;
private PlayerInfoElements[] playerInfoElements = new PlayerInfoElements[4];
private void Start()
{
@@ -45,14 +44,17 @@ public class Client : MonoBehaviour
stream.Write(Encoding.ASCII.GetBytes(roomCode), 0, 10);
string name = PlayerPrefs.GetString("name");
stream.Write(Encoding.ASCII.GetBytes(name), 0, 10);
for (int i = 0; i < playerInfo.Length; i++)
{
playerInfoElements[i] = playerInfo[i].GetComponent<PlayerInfoElements>();
}
new Thread(Read).Start();
}
private void Update()
{
fpsText.text = (int)(Time.frameCount / Time.time) + " FPS";
if (jobs.Count > 0)
{
Job job = jobs.Dequeue();
@@ -112,6 +114,7 @@ public class Client : MonoBehaviour
players[job.data[1]].name = Encoding.ASCII.GetString(name).Replace(" ", "");
players[job.data[1]].index = job.data[1];
players[job.data[1]].textCoinsInfo = playerInfoElements[job.data[1]].textCoinInfo;
players[job.data[1]].Init();
playerNameTexts[job.data[1]].text = Encoding.ASCII.GetString(name).Replace(" ", "");
@@ -121,6 +124,10 @@ public class Client : MonoBehaviour
playerInfo[job.data[1]].SetActive(true);
break;
case 6:
((NoPlayablePlayer)players[job.data[1]]).CoinFieldAction(job.data[2]);
break;
case 126:
stream.Write(new byte[]{126, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 10);
break;
@@ -186,4 +193,9 @@ public class Client : MonoBehaviour
{
stream.Write(new byte[]{5, 0, 0, 0, 0, 0, 0, 0, 0, 0});
}
public void SendCoinFieldAction(int action)
{
stream.Write(new byte[]{6, (byte)action, 0, 0, 0, 0, 0, 0, 0, 0});
}
}
@@ -7,9 +7,14 @@ public class AnimationHandler : MonoBehaviour
{
[SerializeField] private Animator anim;
public void StartAnimation()
public void StartAnimation(Player.AnimationType type)
{
anim.SetInteger("value", 1);
switch (type)
{
case Player.AnimationType.Coin:
anim.SetInteger("value", 1);
break;
}
Invoke("Stop", 0.6f);
}
@@ -30,6 +30,18 @@ public class NoPlayablePlayer : Player
diceScript = dice.GetComponent<Dice>();
}
public void CoinFieldAction(int action)
{
if (action == 0)
{
AddCoins(3);
}
else
{
AddCoins(-3);
}
}
public void Wurfeln(int wurfelZahl)
{
wurfelt = true;
@@ -101,7 +101,12 @@ public class PlayablePlayer : Player
switch (fieldReturnStatus)
{
case 0:
PlayAnimation(AnimationType.Coin);
client.SendCoinFieldAction(0);
AddCoins(3);
break;
case 1:
client.SendCoinFieldAction(1);
AddCoins(-3);
break;
}
+10 -6
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public abstract class Player : MonoBehaviour
@@ -15,6 +16,7 @@ public abstract class Player : MonoBehaviour
protected Vector3 cameraOffset = new Vector3(-2.81f, 8.13f, 5.6f);
public int index;
public int coins = 0;
public TMP_Text textCoinsInfo;
//for coin animation
private AnimationHandler animationHandler;
@@ -41,16 +43,18 @@ public abstract class Player : MonoBehaviour
public void PlayAnimation(AnimationType animationType)
{
switch (animationType)
{
case AnimationType.Coin:
animationHandler.StartAnimation();
break;
}
animationHandler.StartAnimation(animationType);
}
public enum AnimationType
{
Coin
}
protected void AddCoins(int amount)
{
coins += amount;
textCoinsInfo.text = coins + "";
PlayAnimation(AnimationType.Coin);
}
}
@@ -0,0 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PlayerInfoElements : MonoBehaviour
{
public TMP_Text textCoinInfo;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2b65775f940b73c46b505f5402bf704b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: