0

I created a GameObject with a NetworkObject component and attached a script to manage the state of a collider based on the server's status. The script is designed to enable the collider when the server is detected. However, the function responsible for this behavior does not appear to be executing, and no log messages are being shown. Here is the script

public class CanvasNavigation : NetworkBehaviour
{
    public BoxCollider canvasCollider;
    public GameObject canvas;
    public GameObject alertPopUp;
    public GameObject[] pages;
    [Header("Audio")]
    public AudioSource audioSource;
    public AudioClip popUpSound;
    public GameObject semiTruck;
    [Header("Truck Materials")]
    public Material truckMat;
    public Material transparentTruckMat;
    [Space(5)]
    public float cooldownTime = 1f;

    private void Start()
    {
        InitializeCanvasState();
    }

    public override void OnNetworkSpawn()
    {
        canvasCollider.enabled = false;
        base.OnNetworkSpawn();
        if(IsServer)
            canvasCollider.enabled = true;

    }

    private void InitializeCanvasState()
    {
        pages[0].SetActive(true);
        alertPopUp.SetActive(false);
    }

    public void ConfirmActionAndDetachTruck()
    {
        if (IsServer)
        {
            HideCanvas();
            semiTruck.transform.SetParent(null);
        }
    }

    public void CancelActionAndClosePopUp()
    {
        if (IsServer)
        {
            HideAlertPopUp();
        }
    }

    public void SetTruckTransparency(bool isTransparent)
    {
        if (IsServer)
        {
            UpdateTruckMaterialClientRpc(isTransparent);
        }
    }

    [ClientRpc]
    private void UpdateTruckMaterialClientRpc(bool isTransparent)
    {
        Debug.Log("Switching material to: " + (isTransparent ? "Transparent" : "Opaque"));
        Renderer truckRenderer = semiTruck.GetComponent<Renderer>();
        if (truckRenderer != null)
        {
            truckRenderer.material = isTransparent ? transparentTruckMat : truckMat;
        }
    }

    public void ShowAlertAndPlaySound()
    {
        if (IsServer)
        {
            DisplayAlertPopUp();
            audioSource.PlayOneShot(popUpSound);
        }
    }

    private void HideAlertPopUp()
    {
        alertPopUp.SetActive(false);
    }

    private void HideCanvas()
    {
        canvas.SetActive(false);
    }
    private void DisplayAlertPopUp()
    {
        alertPopUp.SetActive(true);
    }
}

i tried putting a log to see if it was atleast being called but it wasnt?

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.