Untitled
unknown
plain_text
4 years ago
1.7 kB
7
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()
{
if (isLocalPlayer)
{
Cmdservere(health, score);
if (Input.GetKeyDown(KeyCode.Space))
{
health -= 1;
}
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
if (health <= 0)
{
NetworkServer.Destroy(gameObject);
}
}
[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...