Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GalaxyCoreLib.Api;
- using GalaxyCoreLib.NetEntity;
- using System;
- using System.Collections;
- using System.Threading;
- using UnityEngine;
- using GalaxyCoreLib;
- public class NetTransform : MonoBehaviour
- {
- /// <summary>
- /// Ссылка на сетевую сущность в ядре
- /// </summary>
- ClientNetEntity netEntity;
- public bool sendMyPosition;
- public bool sendMyRotation;
- private void Awake()
- {
- netEntity = GetComponent<NetEntity>().netEntity;
- }
- private void OnEnable()
- {
- GalaxyEvents.OnFrameUpdate += OnFrameUpdate;
- }
- private void OnDisable()
- {
- GalaxyEvents.OnFrameUpdate -= OnFrameUpdate;
- }
- private void OnFrameUpdate()
- {
- if (!netEntity.isMy) return;
- if (sendMyPosition) netEntity.transform.SendPosition(transform.position.NetworkVector3());
- if (sendMyRotation) netEntity.transform.SendRotation(transform.rotation.NetworkQuaternion());
- }
- public void Update()
- {
- if (!netEntity.isMy)
- {
- transform.position = Vector3.Lerp(transform.position, netEntity.transform.position.Vector3(), GalaxyApi.lerpDelta);
- if (!netEntity.transform.rotation.isZero()) transform.rotation = Quaternion.Lerp(transform.rotation, netEntity.transform.rotation.Quaternion(), GalaxyApi.lerpDelta);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment