Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Let Enviro Know of A Camera Change

Discussion in 'Editor & General Support' started by Hawk0077, Apr 14, 2018.

  1. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    Hi, I am using Enviro and Realistic Car Controller in my project.

    When I ENTER the car the camera changes through a script called: RCC_EnterExitPlayer.cs

    Thing is that the Enviro clouds and settings etc are not carried over to the new camera. ie: Clouds when walking around and clear skies when in the vehicle.

    So I need to tell Enviro there was a change in camera.

    The Enviro developer says I need to add this function just after the camera switch:
    EnviroSky.instance.ChangeFocus(NewPlayer,NewCamera);

    Problem is I am not a developer and only know the very basics of C#. Not enough to know where and how to place the code above.

    So does anyone know where I add the code above: And also do I need to add a class for that to function.

    The only code that I can see that MAY? be where the above function needs placing is:

    Code (csharp):
    1.  
    2. void Start()
    3.             {
    4.  
    5.                 if (!rootOfPlayer)
    6.                     rootOfPlayer = transform.root.gameObject;
    7.  
    8.                 GameObject carCamera = GameObject.FindObjectOfType<RCC_Camera>().gameObject;
    9.                 carCamera.SetActive(false);
    10.  
    11.     }
    12.  
    But placing the above function after that code throws expected compiler errors. (I dont know enough to know exactly what needs doing) Any guidance appreciated to get this working correctly.

    Many thanks.
     
  2. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    197
    From how I understand it, the code line from the Enviro developer should be placed as close as possible after the camera switch. So you would need to find the exact place where the camera change takes place in RCC_EnterExitPlayer.cs. The code snippet you posted looks like some initialization code to me, you can see that the carCamera is being set up so it can be activated later.

    Can you search for "carCamera.SetActive(true);" in "RCC_EnterExitPlayer.cs"? This should be the place where they switch off the other camera and the car camera takes over, and I think you need to place the line of code after that. If you get an compiler error, can you please post the code from the entire function where you placed it & and the full compiler error, if there is any?
     
    Hawk0077 likes this.
  3. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141

    Thanks I will take a look at that file now. Thanks for response.
     
  4. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141

    That code is evident in the EnterExitCar script:

    Code (csharp):
    1.  
    2.  
    3. void GetIn (){
    4.  
    5.         isPlayerIn = true;
    6.  
    7.         carCamera.SetActive(true);
    8.  
    9.         if(carCamera.GetComponent<RCC_Camera>()){
    10.             carCamera.GetComponent<RCC_Camera>().cameraSwitchCount = 10;
    11.             carCamera.GetComponent<RCC_Camera>().ChangeCamera();
    12.         }
    13.  
    14.  
    i WILL TRY ADDING THE eNVIRO SNIPPET.
     
  5. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    Adding that code gives me two errors:

    The name `NewPlayer' does not exist in the current context
    The name `NewCamera does not exist in the current context
     
  6. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    The Enviro developer says that I need to add that code in both places ie: entering car and exiting car which seems to bew the two places you pointed too.

    carCamera.SetActive(true);

    and

    carCamera.SetActive(false);

    So I presume that that I change the Player and Camera name from NewPlayer and New Camera (on EXIT beneath the false statement above) to just MainPlayer and MainCamera.

    But there must need to be something else in the code as adding the Enviro snippet causes the errors above mentioned.

    But thanks for the tips. Im getting closer? I think. lool
     
  7. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    197
    The line of code from the Enviro developer is more like an example, "NewPlayer" and "NewCamera" are supposed to be placeholders since he can't know how the "NewPlayer" and the "NewCamera" is named in your code. I think the following should work:

    Code (CSharp):
    1. EnviroSky.instance.ChangeFocus(this.gameObject,carCamera);
    About the new camera I'm almost 100% sure, for the "NewPlayer" I am assuming that the "RCC_EnterExitPlayer.cs" is a component running on the car GameObject. Therefore we use "this.gameObject" to get the GameObject that this very script is attached on.

    I think we need to do the same in reverse when the player exits the car again. Is there a "Get Out" function or something like that that you can post?
     
    Hawk0077 likes this.
  8. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    Thanks for the response I appreciate it.

    As you can see in the image below:



    The regular third person character (ETHAN) GamerObject is called MainDriver and the Main Camera is Camera just below the third person character.

    Those are added to enviro and when I walk around the scene I get clouds and the rest olf the wether effect.

    The character walks to a vehicle for setup purposes this is located in the vehicle heirarchy called RangeRover_Copper.

    When etrhan gets in that vehicle the camera switches to the RCC_Camera (CarCamera.?).

    I eliminated the previously mentioned errors by adding this to the top of the script called: RCC_EnterExitCar.cs.

    Code (csharp):
    1.  
    2. private GameObject RangeRover_Copper;
    3. private Camera RCC_Camera;
    4.  
    Those are the classes I need to tell Enviro about.

    The problem with that is that there will soon be lots of vehicles not just the one so whatever I do now to make the switch work for the Copper coloured car above will no longer work for the green car version etc.

    And so I changed the Enviro snippet to:

    Code (csharp):
    1.  
    2. EnviroSky.instance.ChangeFocus(RangeRover_Copper, RCC_Camera);
    3.  

    As for your question: Is there a get out function it seems that BOTH are covered in each of the two scripts:

    RCC_EnterExitCar ( this is attached to the car object... EACH car...)
    RCC_EnterExitPlayer (Attached to ETHAN or EACH new Player Game Object).


    THE CODE:

    It seems that the enter and exist are evident in both scripts and the EXIT and ENTER parts are as you first suggested.

    Code (csharp):
    1.  
    2. carCamera.SetActive(true);
    3. carCamera.SetActive(false);
    4.  
    The first mentioned in: RCC_EnterExitCar.cs
    and the second mentioned in: RCC_EnterExitPlayer

    By adding the snippet to the RCC_EnterExitCar.cs script the camera changed on PLAY, But the player ETHAN didnt seem to go with it so the camera was pointing at nothing (not the car).

    My confusion now seems to be that in normal circumstances ETHAN is the player IN and OUT of the car. Or the camera and player automatically change BUT Enviro doesnt know about the switch so needs telling.

    But it seems that only the camera changes? The player just gets in the car?



    It would be better to do this with TAGS I think but not sure how to do that either. I could then have EVERY car with the same tag? then just use the RCC_Camera.

    Anyways thanks for the push, I could be getting closer but not so sure? lol.

    Thanks
     
  9. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    197
    Ok, I was assuming the player would be destroyed / deactivated / would not move with the vehicle during the time it is inside the car. As far as I know Enviro only requires the player so it knows at which position in the game world it should display the clouds and weather etc. So if the player is still active this would make things easier....

    Can you enter play mode and watch closely what happens to the MainDriver GameObject when you enter a car?
    If the MainDriver GameObject stays active in the car, and is being moved with the car, we can just tell Enviro to use its current player again (camera part intentionally left out, we will get to that):
    Code (CSharp):
    1. EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, XXXXXXXXXX);
    For the camera part: Can you check if your regular camera (the one inside "Characters & Cameras" in the hierarchy) is tagged as "MainCamera"? If yes, we could use these two line of codes every time RCC_EnterExitCar.cs activates / deactivates its own camera. Search for every line of "carCamera.SetActive" in the code, and change it like this, depending if it is .SetActive(true) or .SetActive(false):

    Code (CSharp):
    1. carCamera.SetActive(true);
    2. EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, carCamera);
    Code (CSharp):
    1. carCamera.SetActive(false);
    2. EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, Camera.main);
    This should work for every car as well, since carCamera will always point to the correct camera of the current car, and Camera.main should always return your regular camera.

    I hope the changes are not too confusing, the problem is that there are 100s ways of doing this, so every time I get new info about your project I'm thinking "Ok if it is like this and that, then this solution would probably the easiest to get across in a forum post" ;)
     
    Hawk0077 likes this.
  10. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    Thanks again for the help and response OneManBandGames...

    Can you enter play mode and watch closely what happens to the MainDriver GameObject when you enter a car?

    The MainDriver is visible when entering play mode but then Disappears on entering the car.

    Can you check if your regular camera (the one inside "Characters & Cameras" in the hierarchy) is tagged as "MainCamera"?

    Yes it is tagged MainCamera.

    I will try adding the code for the setActive options you mentioned above.

    Thanks again, much appreciated for your efforts..

    I will post the result here shortly.

    .
     
  11. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    Changing the two instances of the setActive function seems to have done the job matey.

    Thanks very much for your assist. I am going to dig a little deeper into coding in a month or so when the main terrain is in place. But thanks again for the great efforts you made to help me solve this.

    Very much appreciated.

    I have a few other things I need to address so I may hear from you in the future too. Many thanys again.
     
    OneManBandGames likes this.
  12. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    197
    Glad to hear it is working now! :)
     
    Hawk0077 likes this.
  13. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    Blowey Fish Looks really funny and complex C# knowledge required. Il get there one day. All the best. And thanks.
     
  14. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    I have just upgraded Realistic Car Controller and the solution above no longer works because the scripting is completely different and Im not so sure of the exact details to get it working again.

    From what I can see this is the new section of code in a file called RCC_Camera.

    Code (CSharp):
    1. public void RemoveTarget(){
    2.  
    3.         transform.SetParent (null);
    4.  
    5.         playerCar = null;
    6.         playerRigid = null;
    7.  
    8.     }
    9.  
    10.     void Update(){
    11.  
    12.         // If it's active, enable the camera. If it's not, disable the camera.
    13.         if (!isRendering) {
    14.  
    15.             if(cam.gameObject.activeInHierarchy)
    16.                 cam.gameObject.SetActive (false);
    17.             //EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, Camera.main);
    18.  
    19.             return;
    20.  
    21.         } else {
    22.  
    23.             if(!cam.gameObject.activeInHierarchy)
    24.                 cam.gameObject.SetActive (true);
    25.             // EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, cam);
    26.            
    27.  
    28.         }
    29.  
    30.         // Early out if we don't have the player vehicle.
    31.         if (!playerCar || !playerRigid){
    I added the above lines in an attempt to get it working again and to switch cameras to show the enviro sky/clouds etc but that didnt make any difference.

    I took the "cam" variable above from the start of the RCC_Camera file:

    Code (CSharp):
    1. // The target we are following transform and rigidbody.
    2.     public RCC_CarControllerV3 playerCar;
    3.     private Rigidbody playerRigid;
    4.     private float playerSpeed = 0f;
    5.  
    6.     public Camera cam;                // Camera is not attached to this main gameobject. Camera is parented to pivot gameobject. Therefore, we can apply additional position and rotation changes.
    7.     public GameObject pivot;        // Pivot center of the camera. Used for making offsets and collision movements.
    8.  
    The above changes I made seemed to work in that when out of the car: The clouds were just groups of dots and not rendered correctly.,

    Also when in the car the same thing occurred. Just groups of dots.


    Any direction to get this working again very much appreciated, thanks.
     
  15. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    197
    I think you almost got it correct, the only problem is that you need to add brackets to the if-statements. When an if-statement has no brackets, it is only valid for the next line of code until the next semicolon ";". I think what then happened is that your line with the camera change was executed over and over again so Enviro did not render the clouds correctly because it was permanently updating the camera.

    Can you try this code instead:

    Code (CSharp):
    1. // If it's active, enable the camera. If it's not, disable the camera.
    2.         if (!isRendering) {
    3.             if(cam.gameObject.activeInHierarchy) {
    4.                 cam.gameObject.SetActive (false);
    5.                 EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, Camera.main);
    6.             }
    7.             return;
    8.         } else {
    9.             if(!cam.gameObject.activeInHierarchy) {
    10.                 cam.gameObject.SetActive (true);
    11.                 EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, cam);
    12.             }      
    13.         }
     
    Hawk0077 likes this.
  16. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    141
    AWESOME, thanks very much @OneManBandGames that did the trick. Much appreciated.