Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Can only despawn onject from the server side

Discussion in 'Lobby' started by shivadgss, Jun 25, 2023.

  1. shivadgss

    shivadgss

    Joined:
    Apr 1, 2022
    Posts:
    1
    I am trying to make a simple clicking game where when you click an object the object disappears and score increase. I am able to do it on the server side but not on the client side how do I resolve it

    using System;
    using Unity.Netcode;
    using Unity.VisualScripting;
    using UnityEngine;

    public class AppleClicker : NetworkBehaviour
    {
    private void OnMouseDown()
    {
    // Destroy the clicked apple GameObject
    if(!IsOwner) return;
    NetworkObject.Despawn();

    // Notify the ScoreManager about the score change
    ScoreManager.Instance.IncrementScore();
    }
    }
     
  2. JeromeIsntDev

    JeromeIsntDev

    Joined:
    Nov 23, 2021
    Posts:
    5
    You'll have to use RPCs. I recommend looking at CodeMonkey's Video on YouTube about Networking with GameObjects.