71 lines
1.3 KiB
C#
71 lines
1.3 KiB
C#
using UnityEngine;
|
|
using Mirror;
|
|
|
|
public class Boat : NetworkBehaviour
|
|
{
|
|
public AudioSource audioSource;
|
|
|
|
[SyncVar(hook = nameof(OnStateChanged))]
|
|
public bool state = false;
|
|
|
|
public GameObject wall;
|
|
public GameObject hubFog;
|
|
public Transform parkPoint;
|
|
|
|
public float speed;
|
|
|
|
public void Interact()
|
|
{
|
|
CmdInteract();
|
|
}
|
|
|
|
[Command(requiresAuthority = false)]
|
|
private void CmdInteract(NetworkConnectionToClient sender = null)
|
|
{
|
|
// RpcInteract();
|
|
state = true;
|
|
}
|
|
|
|
// [ClientRpc]
|
|
// private void RpcInteract()
|
|
// {
|
|
|
|
// }
|
|
|
|
public void Play()
|
|
{
|
|
audioSource.Play();
|
|
hubFog.SetActive(false);
|
|
}
|
|
|
|
void OnStateChanged(bool oldState, bool newState)
|
|
{
|
|
if (newState)
|
|
{
|
|
Play();
|
|
}
|
|
else
|
|
{
|
|
wall.SetActive(false);
|
|
audioSource.Stop();
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!isServer) return;
|
|
|
|
bool arrived = Vector3.Distance(transform.position, parkPoint.position) < 1;
|
|
|
|
if (state && !arrived)
|
|
{
|
|
transform.localPosition += transform.forward * speed * Time.deltaTime;
|
|
}
|
|
|
|
if (arrived)
|
|
{
|
|
state = false;
|
|
}
|
|
}
|
|
}
|