FlappyBirdMP/Assets/Scripts/Pipe.cs
2025-06-23 00:38:12 +05:30

45 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Mirror;
using UnityEngine;
public class Pipe : NetworkBehaviour
{
[SyncVar]
public double startedTime;
[SyncVar]
public float startedX;
public void Setup(float _startedX, float spaceBetween){
if(!isServer){
Debug.Log("Forbidden to run not on server");
return;
}
startedTime = NetworkTime.time;
startedX = _startedX;
SetInnerSpace(spaceBetween);
RpcSetup(_startedX, spaceBetween);
}
[ClientRpc]
void RpcSetup(float _startedX, float spaceBetween){
SetInnerSpace(spaceBetween);
}
void SetInnerSpace(float space){
Transform bottomPipe = transform.GetChild(0);
Transform topPipe = transform.GetChild(1);
bottomPipe.position += new Vector3(0, space, 0);
topPipe.position -= new Vector3(0, space, 0);
}
void Update(){
double timeDelta = startedTime - NetworkTime.time;
float dist = LevelsManager.pipeMovingSpeed * (float)timeDelta;
float newX = startedX + dist;
transform.position = new Vector3(newX, transform.position.y, transform.position.z);
}
}