Hello, I’m a newcomer to Unity, and I wanted to create SCP-173 for my multiplayer game (using Photon). I’ve written the code for single-player mode, but I don’t quite understand how to adapt it for multiplayer. The default object has Photon View and Photon Transform attached to it. Could you please help me with this issue? Here’s the code:
using System.Collections;
using UnityEngine;
using UnityEngine.AI;
using System.Collections.Generic;
using TMPro;
using Photon.Realtime;
using ParrelSync.NonCore;
using Unity.VisualScripting;
using System.Security.Cryptography;
using Photon.Pun;
public class Morganie : MonoBehaviourPunCallbacks
{
public GameObject _blackScreen;
public bool _isLookingOnObject;
public bool _isWall;
Transform pla;
RaycastHit hit;
private bool timerRunning = false;
private bool hasBlinkBeenZero = false;
public NavMeshAgent _objectNavMeshObject;
private void OnTriggerStay(Collider other)
{
pla = other.transform;
if (other.CompareTag("Player"))
{
if (!timerRunning)
{
//timerRunning = true;
//StartCoroutine(StartTimer(8f));
}
if (Input.GetAxis("Blink") > 0)
{
print("Работаю1");
_isLookingOnObject = false;
_blackScreen.SetActive(true);
hasBlinkBeenZero = false;
}
else
{
if (!hasBlinkBeenZero)
{
print("Работаю");
_isLookingOnObject = true;
_blackScreen.SetActive(false);
hasBlinkBeenZero = true;
}
}
Wall();
if (_isLookingOnObject == false)
{
MoveObj(other);
}else
{
if (_isWall)
{
MoveObj(other);
}
else
{
_objectNavMeshObject.SetDestination(gameObject.transform.position);
}
}
}
}
void OnBecameVisible()
{
_isLookingOnObject = true;
}
void OnBecameInvisible()
{
_isLookingOnObject = false;
}
IEnumerator StartTimer(float duration)
{
_blackScreen.SetActive(true);
_isLookingOnObject = false;
print("Первое срабатавание таймера");
yield return new WaitForSeconds(0.2f);
_blackScreen.SetActive(false);
_isLookingOnObject = true;
print("Второе срабатавание таймера");
yield return new WaitForSeconds(7f);
timerRunning = false;
}
void Wall()
{
Vector3 start = pla.position + Vector3.up * 1.5f;
Vector3 end = transform.position + Vector3.up * 1.5f;
if (Physics.Linecast(start, end, out hit))
{
// Проверяем, столкнулся ли луч с каким-то объектом
if (!hit.collider.CompareTag("Player") && hit.collider != pla)
{
Debug.DrawLine(start, end, Color.red);
_isWall = true;
return;
}
}
else
{
Debug.DrawLine(start, end, Color.green);
}
_isWall = false;
}
private void MoveObj(Collider other)
{
_objectNavMeshObject.SetDestination(other.transform.position);
gameObject.transform.LookAt(other.transform.position);
}
}