Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Assigning Authority

Discussion in 'Connected Games' started by awesomesid123, Feb 8, 2018.

  1. awesomesid123

    awesomesid123

    Joined:
    Oct 4, 2014
    Posts:
    23
    So I recently created a script in order to assign authority to players on when they come in contact with an interactable football. But the script shows errors. Please help.

    Script :

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Networking;

    public class authority : MonoBehaviour {
    public GameObject Obj;

    // Use this for initialization
    void Start () {
    Obj = GameObject.Find("Multiplayer_Player(Clone)");
    }


    // Update is called once per frame
    void Update () {

    }

    private void OnTriggerEnter(Collider other)
    {
    if (other.tag == "football")
    {
    Cmd_AssignLocalAuthority;
    }
    }
    private void OnTriggerExit(Collider other)
    {
    if (other.tag == "football")
    {
    if (other.tag == "football")
    {
    Cmd_RemoveLocalAuthority;
    }
    }
    }

    [Command]
    void Cmd_AssignLocalAuthority (GameObject Obj)
    {
    NetworkInstanceId nIns = Obj.GetComponent<NetworkIdentity> ().netId;
    GameObject client = NetworkServer.FindLocalObject (nIns);
    NetworkIdentity ni = client.GetComponent<NetworkIdentity> ();
    ni.AssignClientAuthority(client);
    }

    [Command]
    void Cmd_RemoveLocalAuthority (GameObject Obj) {
    NetworkInstanceId nIns = Obj.GetComponent<NetworkIdentity> ().netId;
    GameObject client = NetworkServer.FindLocalObject (nIns);
    NetworkIdentity ni = client.GetComponent<NetworkIdentity> ();
    ni.RemoveClientAuthority (client);
    }
    }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    2,700
    1) Use code tags on the forum to make your code readable, or few will even try reading it
    2) No one will help with code errors if you aren't going to say what the code errors are
    3) No one will help with errors if you aren't going to say what line number the error occurs
     
  3. awesomesid123

    awesomesid123

    Joined:
    Oct 4, 2014
    Posts:
    23
    The error occurs in the lines which say : "ni.RemoveClientAuthority (client);" and "ni.AssignClientAuthority(client);"
    The error is not shown in the console but whenever I try to build the game it says please fix all compiler errors. So now I hope you are in a better position of helping me out here :)
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    2,700
    You still haven't even said what the error is......

    It looks like you're calling both of your Command methods incorrectly though. They are declared as "void Cmd_RemoveLocalAuthority(GameObject Obj)" but you're not putting the () after or passing any GameObject.
     
  5. awesomesid123

    awesomesid123

    Joined:
    Oct 4, 2014
    Posts:
    23
    So I finally found out that the error I was getting was that whenever the object enters the collider it gives an error saying that authorities can only be assigned for server spawned objects. Thank you so much for your patience.