【发布时间】:2021-09-26 02:40:03
【问题描述】:
嗯,所以我尝试使用光子 RPC,但它似乎没有通过网络发送信息?
目前,当玩家射击时,它只能在他们的 PC 上显示,但在同一个房间里玩的其他人看不到它
PlayerShoot.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class playerShoot : MonoBehaviourPunCallbacks
{
public Transform shootPoint;
public LineRenderer gunLine;
public float range = 30f;
RaycastHit hit;
Ray ray;
public PhotonView photonview;
// Start is called before the first frame update
void Start()
{
gunLine = GetComponent<LineRenderer>();
photonview = PhotonView.Get(this);
}
// Update is called once per frame
void Update()
{
if (!photonView.IsMine)
return;
photonview.RPC("shoot",RpcTarget.All);
//shoot();
}
[PunRPC]
public void shoot()
{
if (!photonView.IsMine)// still need to call this coz the one in update doesn't seem to work?
return;
if (Input.GetButton("Fire1"))
{
gunLine.enabled = true;
gunLine.SetPosition(0, shootPoint.position);
ray.origin = shootPoint.position;
ray.direction = transform.forward;
if (Physics.Raycast(ray, out hit, range))
{
//Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.red);
Debug.Log(hit.point);
gunLine.SetPosition(1, hit.point);
}
else
{
gunLine.SetPosition(1, ray.origin + ray.direction * range);
}
}
else
gunLine.enabled = false;
}
}
显示问题的视频:
【问题讨论】:
标签: c# visual-studio unity3d photon