7- Player Networking (Camera Control): The type or namespace name 'CameraWork' could not be found

Hi, I am making the Tutorial, and in the 7. Player Networking - Camera Control part, it says:
Open the PlayerManager script.
Insert the code below in between Awake() and Update() methods 
/// <summary>
/// MonoBehaviour method called on GameObject by Unity during initialization phase.
/// </summary>
void Start()
{
    CameraWork _cameraWork = this.gameObject.GetComponent<CameraWork>();


    if (_cameraWork != null)
    {
        if (photonView.IsMine)
        {
            _cameraWork.OnStartFollowing();
        }
    }
    else
    {
        Debug.LogError("<Color=Red><a>Missing</a></Color> CameraWork Component on playerPrefab.", this);
    }
}
Save the Script PlayerManager
First, it gets the CameraWork component, we expect this, so if we don't find it, we log an error. Then, if photonView.IsMine is true, it means we need to follow this instance, and so we call _cameraWork.OnStartFollowing() which effectivly makes the camera follow that very instance in the scene.
All other player instances will have their photonView.IsMine set as false, and so their respective _cameraWork will do nothing.
One last change to make this work:
Disable Follow on Start on the CameraWork component on the prefab My Robot Kyle
I get this error:
Assets\SCRIPTS\PlayerManager.cs(52,13): error CS0246: The type or namespace name 'CameraWork' could not be found (are you missing a using directive or an assembly reference?)

Comments

  • josecm
    josecm
    edited July 2019
    I got fixed it. The problem was in the 5 Part, https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/player-prefab#camera_setup

    in the Camera Setup section says:
    Camera Setup
    In this section, we are going to use the CameraWork script. If you want to write CameraWork from scratch, please go to the next part and come back here when done.
    
    Add the component CameraWork to My Kyle Robot prefab.
    Turn on the property Follow on Start, which effectually makes the camera instantly follow the character. We'll turn it off when we'll start network implementation.
    Set the property Center Offset to 0,4,0 which makes the camera look higher, and thus gives a better perspective of the environment than if the camera was looking straight at the player, we would see too much ground for nothing.
    Play the scene Kyle Test, and move the character around to verify the camera is properly following the character.
    And the component CameraWork that is on the PUN folder have a different namespace (namespace Photon.Pun.Demo.PunBasics) at the start of this script. Change it to:
    namespace Com.MyCompany.MyGame{

    And it works now.
  • It don´t show the error but now it don´t find the CameraWork component at runtime. I also tried with the finished demo that comes with the Photon package and happen the same:
    <a>Missing</a></Color> CameraWork Component on playerPrefab.
    UnityEngine.Debug:LogError(Object, Object)
    Com.MyCompany.MyGame.PlayerManager:Start() (at Assets/SCRIPTS/PlayerManager.cs:101)
    Any ideas?

    Thanks in advance.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @josecm,

    We cannot understand what you are trying to describe.
    Try to rephrase and answer the following questions:

    - what is the issue exactly? is it in the demo code? is it in the documentation of the demo? or in your own custom code?
    - can you reproduce with the demo scene in a fresh empty clean new project with just PUN imported?
    - what is the expected behaviour? what is the actual behaviour?
    - what PUN version are you using?
    - what Unity version are you using?
  • josecm
    josecm
    edited July 2019
    Hi, sorry by my english.

    I was doing exactly the steps from the "PUN Basics Tutorial".

    1. The first issue was (I SOLVED IT) that I got the follow error:
    Assets\SCRIPTS\PlayerManager.cs(52,13): error CS0246: The type or namespace name 'CameraWork' could not be found (are you missing a using directive or an assembly reference?

    The problem was that in the tutorial (5 part) says:
    Camera Setup
    In this section, we are going to use the CameraWork script. If you want to write CameraWork from scratch, please go to the next part and come back here when done.
    Add the component CameraWork to My Kyle Robot prefab...


    I added the CameraWork script that was in the Demo folder and it had a namespace called:
    Photon.Pun.Demo.PunBasics

    AND IT MUST BE:
    Com.MyCompany.MyGame

    I changed it to Com.MyCompany.MyGame and now Works correctly and do not show the error above.


    2. After I solved the point 1 above, i notice that the Script code don´t Find the CameraWork script in real time (to follow my own player):
    Missing CameraWork Component on playerPrefab.
    UnityEngine.Debug:LogError(Object, Object)
    Com.MyCompany.MyGame.PlayerManager:Start() (at Assets/SCRIPTS/PlayerManager.cs:101)


    I found other threads that have the same problem, but they was a bit old threads. If I found then again i will post them here.

    The problem now is that the camera don´t follow my player. Also happen in other instances (EXE).

    I just tried with a new Proyect and just imported PUN2. I tested the Demo and all Works correctly. The camera follow the players.

    But in the Proyect I am making the tutorial, if I open the Demo the camera do NOT follow the player, like happen in my scene I am doing the tutorial.


    I use:
    PUN2 version 2.13
    UNITY version 2018.3.8 f1
  • Hello there,

    I think you should not change the namespace "Photon.Pun.Demo.PunBasics" in CameraWork script to your namespace. That may cause some weird errors.

    Instead, just "using Photon.Pun.Demo.PunBasics;" in your script in which you want to use the CameraWork, then the compiler can find that class.
  • mEKG
    mEKG
    edited July 2020
    Yes, "using Photon.Pun.Demo.PunBasics;" fix the problem here :)
    But why can't change the namespace? What if I want to integrate this code into another project?
  • samm
    samm
    edited December 2021

    I have the same problem.

    The namespace on cameraworks is photon.pun.demo.punbasics but the camera doesn't follow the player at all. (i deleted the main camera by mistake and created a new one, does that have anything to do with it?)

    my PlayerAnimatorManager script doesn't allow class monobehaviourpun with my company namespace, only with namespace photon.pun.demo.punbasics

    playermanager script doesn't accept camerawork references if the namespace of camerawork script is not set to my company.

    there are so many errors! help!