Untitled
unknown
plain_text
2 months ago
1.6 kB
4
Indexable
using System.Collections; using UnityEngine; using UnityEngine.Networking; using Photon.Pun; public class BattleRoyalePlayer : MonoBehaviourPunCallbacks { public float moveSpeed = 5f; public float jumpForce = 5f; public Camera playerCamera; public Rigidbody rb; public GameObject bulletPrefab; public Transform firePoint; public int health = 100; void Update() { if (!photonView.IsMine) return; // Movement float moveX = Input.GetAxis("Horizontal") * moveSpeed; float moveZ = Input.GetAxis("Vertical") * moveSpeed; Vector3 move = transform.right * moveX + transform.forward * moveZ; rb.velocity = new Vector3(move.x, rb.velocity.y, move.z); // Jump if (Input.GetKeyDown(KeyCode.Space)) { rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z); } // Shooting if (Input.GetMouseButtonDown(0)) { photonView.RPC("Shoot", RpcTarget.All); } } [PunRPC] void Shoot() { GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation); Rigidbody bulletRb = bullet.GetComponent<Rigidbody>(); bulletRb.velocity = firePoint.forward * 20f; Destroy(bullet, 3f); } [PunRPC] public void TakeDamage(int damage) { health -= damage; if (health <= 0) { PhotonNetwork.Destroy(gameObject); } } }
Editor is loading...
Leave a Comment