1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SynchronizationObject : MonoBehaviour
- {
- public SyncObjectType type;
- public bool isSync;
- public string uid;
- private SyncObject data;
- private float Speed = 3;
- private float framSpeed;
- private float dis;
- private float pross;
- private void Start()
- {
- MultiPlayerManager.Instance.OnSynObject += OnSyncObject;
- }
- public void InitData(SyncObject data)
- {
- if (data != null)
- return;
- this.data = data;
- }
- public void OnSyncObject(SyncObject data)
- {
- if (data.id == uid)
- this.data = data;
- }
- private void Update()
- {
- if(type == SyncObjectType.Player)
- if (data != null && transform.localPosition != data.pos)
- {
- framSpeed = Time.deltaTime * Speed;
- dis = Vector3.Distance(transform.localPosition, data.pos);
- pross = 0;
- if (framSpeed > dis)
- {
- transform.localPosition = data.pos;
- }
- else
- {
- pross = framSpeed / dis;
- transform.localPosition = Vector3.Lerp(transform.localPosition, data.pos, pross);
- }
- }
- }
- }
|