#Is it possible to trigger OnTriggerStay function but only on Server?
1 messages · Page 1 of 1 (latest)
You can decorate it with [ServerCallback].
i know, but that will still run on client too
actually... i don't understand something obviously :S
using UnityEngine;
using Mirror;
public class BallDetection : MonoBehaviour
{
private Rigidbody _rigidbody;
private void Awake()
{
_rigidbody = GetComponentInParent<Rigidbody>();
}
[ServerCallback]
private void OnTriggerStay(Collider other)
{
if (!other.CompareTag("Player")) return;
Vector3 pushDir = (transform.position - other.transform.position).normalized;
_rigidbody.AddForce(pushDir * 1f, ForceMode.Impulse);
}
}
I have this script on a sphere object,
and it has collision enabled and when a Player collides with it, I want it to move,
but now it only works when server does it
why it doesn't work with other clients?
use
#if UNITY_SERVER
// YOUR CODE
#endif
this way this code won't even be compiled in client
that is the same as [Server] right?
Nope
That's for server builds
The server callback makes any function run on the server only