Вот мой код CameraTracking:
CameraTracking.cs
Код: Выделить всё
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraTracking : MonoBehaviour
{
public Transform playerCharacter;
Vector3 cameraOffset;
void Start()
{
if (playerCharacter != null)
{
cameraOffset = transform.position - playerCharacter.position;
Debug.Log("Player character transform is assigned: " + playerCharacter.name);
}
else
{
Debug.LogError("Player character transform is not assigned to CameraTracking script!");
}
}
void Update()
{
if (playerCharacter != null)
{
transform.position = playerCharacter.position + cameraOffset;
}
}
}
Код: Выделить всё
using Photon.Pun;
using Photon.Pun.UtilityScripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Multiplayer : MonoBehaviour, IPunObservable
{
[HideInInspector]
public float movementSpeed = 10f;
public float fireRate = 0.75f;
public int health = 100;
public Slider healthBar;
Rigidbody rigidBody;
public GameObject bulletPrefab;
public Transform bulletPosition;
float nextFire;
public AudioClip playerShootingAudio;
public GameObject bulletFiringEffect;
PhotonView photonView;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent();
photonView = GetComponent
();
}
// Update is called once per frame
void FixedUpdate()
{
if (!photonView.IsMine)
return;
Move();
if (Input.GetKey(KeyCode.Space))
photonView.RPC("Fire", RpcTarget.AllViaServer);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Bullet"))
{
MultiplayerBulletController bullet = collision.gameObject.GetComponent();
TakeDamage(bullet);
}
}
void TakeDamage(MultiplayerBulletController bullet)
{
health -= bullet.damage;
healthBar.value = health;
if (health nextFire)
{
nextFire = Time.time + fireRate;
GameObject bullet = Instantiate(bulletPrefab, bulletPosition.position, Quaternion.identity);
bullet.GetComponent()?.InitializeBullet(transform.rotation * Vector3.forward, photonView.Owner);
AudioManager.Instance.Play3D(playerShootingAudio, transform.position);
VFXManager.Instance.PlayVFX(bulletFiringEffect, bulletPosition.position);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(health);
}
else
{
health = (int)stream.ReceiveNext();
healthBar.value = health;
}
}
}
Заранее спасибо.
p>
Я не силен ни в разработке игр, ни в C#. Это всего лишь модуль по информатике, о котором я сожалею. Я попробовал много разных методов, проверил все возможные форумы и задал ChatGPT 1000000 раз, но все равно ничего. Я начал обучение с самого начала и снова столкнулся с той же проблемой. Думаю, проблема в учебнике.
Подробнее здесь: https://stackoverflow.com/questions/787 ... vements-no