45 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|