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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

How to use my own object in "using" rather than the "UnityStandardAssets"?

Discussion in 'Scripting' started by SkinnyFG, Mar 17, 2018.

  1. SkinnyFG

    SkinnyFG

    Joined:
    Aug 31, 2014
    Posts:
    5
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Networking;
    using UnityStandardAssets.Characters.FirstPerson;

    alright so I want to call my own FirstPersonCharacter rather than from the UnityStandardAssets.
    The prefab is called "PlayerUnit", and my own object with the FirstPersonCharacter is listed as "Player"

    How would I go about "using" my own object?
    I mean something like

    using PlayerUnit.Player.FirstPersonCharacter;

    \/ Rest of my script \/


    namespace GTGDS1
    {

    public class Player_Network : NetworkBehaviour {

    public GameObject firstPersonCharacter;
    public GameObject[] characterModel;

    public override void OnStartLocalPlayer()
    {
    GetComponent<FirstPersonController>().enabled = true;
    firstPersonCharacter.SetActive(true);

    foreach (GameObject go in characterModel)
    {
    go.SetActive(false);
    }
    }

    }

    }
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Using statements refer to the namespace

    So in your case
    using GTGDS1;

    Or when you getComponent

    GetComponent<GTGDS1.FirstPersonCharacter>()

    The using has nothing to do with the prefab or the name of the gameobject.
    Also note you might want to remove the Unity's using if the scripts are named the same. (and you're not using the Unity one in that script to avoid conflicts)
     
  3. SkinnyFG

    SkinnyFG

    Joined:
    Aug 31, 2014
    Posts:
    5
    I appreciate it! I’m gonna try that out!
     
  4. SkinnyFG

    SkinnyFG

    Joined:
    Aug 31, 2014
    Posts:
    5
    So I am still confused, sorry I am brand new to scripting.
    What I'm trying to do, is disable the FirstPersonController of other players so I don't take control of them as a client.
    I want everyone to control their own player while the server maintains the position of everyone.
    My script. \/
     

    Attached Files:

    • del.png
      del.png
      File size:
      205 KB
      Views:
      622
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If I can offer a friendly suggestion... When you're brand new to scripting, try to write a single player game first (possibly more than 1) before you attempt multiplayer.
     
  6. SkinnyFG

    SkinnyFG

    Joined:
    Aug 31, 2014
    Posts:
    5
    I appreciate it but any ideas of how to fix my issue though?
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You should put the namespace back in, as you had in your original post. You were confused that using your own name would be necessary...At least, I think so.
    That is the namespace, and your prefab can be whatever you want.. it's unrelated.

    Did you actually create your own class for the first person controller, or you really are using the standard asset one?
     
  8. SkinnyFG

    SkinnyFG

    Joined:
    Aug 31, 2014
    Posts:
    5
    It is the standard asset firstpersoncontroller
     
  9. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ya, okay, then you have to add the namespace back in (or use its fully qualified name in your call to GetComponent). That should fix the error in the screenshot.