Untitled
unknown
csharp
4 years ago
1.6 kB
3
Indexable
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Mirror; using TMPro; public class PlayerControllers : NetworkBehaviour { public GameObject menu; public int bulletdamage = 5; public sbyte moveSpeed = 5; public int score; public Rigidbody2D rb; Vector2 movement; public int health; public string altimizdakitext; public TMP_Text altimizdakitextobject; private void Start() { if(isLocalPlayer) menu = GameObject.FindGameObjectWithTag("Respawn"); } private void Update() { // Bu kısma tüm player'ların ortak yapacağı şeyleri yaz. Ayrıca verileri server'la eşitlemek istiyorsan [SyncVar]'lara bak! if (isLocalPlayer) return; // Bu kısıma sadece şu an kontrol edebilidğim oyuncunun kodunu yaz, mesela hareket kontrolü vs. } [Command] public void Cmdservere(int healthx, int scorex) { health = healthx; score = scorex; Cmdcliente(healthx, scorex); } [ClientRpc] public void Cmdcliente(int healthx, int scorex) { altimizdakitext = "Health: " + healthx + " Nick: nothing " + "Score: " + scorex; altimizdakitextobject.text = altimizdakitext; } private void OnDestroy() { if (isLocalPlayer) menu.SetActive(true); } private void FixedUpdate() { rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime); } }
Editor is loading...