Search Unity

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

Question Variables in the prefab cannot be set.

Discussion in 'Multiplayer' started by somedevelopergg, Sep 26, 2021.

  1. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    I am making a multiplayer game and I am facing a problem. in the prefab, i cannot set object / UI variables, like, completely. And there are a lot of variables and I cannot write for each search by tag or something else. Can anyone tell me how to solve this or an alternative way of the player appearing on the scene without a prefab?
    upload_2021-9-26_21-56-0.png
     
  2. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    i kinda got the solution, but just to check: is this ok?


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using Mirror;
    6.  
    7. public class StatsBank : MonoBehaviour
    8. {
    9.     public HpStuff HpS;
    10.     public Cursor_building curs;
    11.     void Start()
    12.     {
    13.         GameObject gpl = GameObject.FindGameObjectWithTag("StatsBank");
    14.         HpStuff hpl = gpl.GetComponent<HpStuff>();
    15.         HpS.HpBar = hpl.HpBar;
    16.         HpS.MetallBar = hpl.MetallBar;
    17.         HpS.Handle = hpl.Handle;
    18.         HpS.InventStuff = hpl.InventStuff;
    19.     }
    20.  
    21.  
    22. }
    23.