Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Object automatically disappears a short time after it is created

Discussion in 'Multiplayer' started by choandepzai321, Dec 6, 2023.

  1. choandepzai321

    choandepzai321

    Joined:
    May 8, 2022
    Posts:
    1
    Hello, I'm making Multiplay mode for a game to be used for a graduation project. And currently I'm encountering an error that only appears on the built application but does not appear on the clone editor (Parrelsync). In particular, the bullet is successfully spawned, then the bullet moves for a while and finally disappears even though there is no call to the Destroy() function in the code.
    Code (CSharp):
    1. class Player : NetworkBehavior{
    2.  
    3. void Update{
    4.         if (Input.GetMouseButtonUp(0) && IsOwner && IsServer)
    5.         {
    6.  
    7.             //only shoot if there is enough power applied to the shoot
    8.             if (shootPower >= minShootPower)
    9.             {
    10.                 ShootArrowClientRpc();
    11.             }
    12.  
    13.         }
    14. }
    15.  
    16.     [ClientRpc]
    17.     void ShootArrowClientRpc()
    18.     {
    19.         shootArrow();
    20.     }
    21.  
    22.  
    23. void shootArror()
    24. {
    25.      projectile = Instantiate(arrow, playerShootPosition.transform.position, Quaternion.Euler(0, 180, shootDirection * -1));
    26.         projectile.GetComponent<MainLauncherNetworkController>().playerShootVector = shootDirectionVector * ((100 + baseShootPower) / 50);
    27.         projectile.GetComponent<NetworkObject>().Spawn();
    28. }
    29.  
    30. }