Search Unity

What's EOF (read description)?

Discussion in 'Scripting' started by Treasureman, Oct 12, 2014.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    I have a script that is going to toggle between "LeftCamera"
    And "RightCamera" When the input "SwitchShoulders" is tapped. But I keep getting a compiler error saying I need to replace "}" with "EOF" on the 22nd line of scripting, but I don't know what EOF is or how to write it. Here's the script:

    1. var LeftCamera :Camera;
    2. var RightCamera :Camera;
    3. functionStart(){
    4. LeftCamera.enabled =true;
    5. RightCamera.enabled =false;
    6. }
    7. functionUpdate(){
    8. if(Input.GetButtonDown("SwitchShoulders"))
    9. if( LeftCamera.enabled ==true){
    10. RightCamera.enabled =true;
    11. LeftCamera.enabled =false;
    12. }
    13. elseif (RightCamera.enabled ==true){
    14. LeftCamera.enabled =true;
    15. RightCamera.enabled =false;
    16. }
    17. }
    18. };
    Here's my question, what's EOF, how do I write it, and where do I write it?
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    When posting code please use code tags.

    EOF stands for End Of File. The compiler is expecting the file to end, but instead it found a '}' meaning you have an extra '}'

    You also have an unnecessary semicolon at the end.
     
  3. bara1247

    bara1247

    Joined:
    Oct 22, 2012
    Posts:
    40
    Code (JavaScript):
    1. var LeftCamera : Camera;
    2. var RightCamera : Camera;
    3.  
    4.  
    5. functionStart()
    6. {
    7.     LeftCamera.enabled = true;
    8.     RightCamera.enabled = false;
    9. }
    10.  
    11.  
    12. functionUpdate()
    13. {
    14.     if (Input.GetButtonDown("SwitchShoulders"))
    15.     {
    16.  
    17.         if (LeftCamera.enabled == true)
    18.         {
    19.             RightCamera.enabled = true;
    20.             LeftCamera.enabled = false;
    21.         }
    22.         else if (RightCamera.enabled == true)
    23.         {
    24.             LeftCamera.enabled = true;
    25.             RightCamera.enabled = false;
    26.         }
    27.     }
    28. }
    29.  
     
  4. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    Thanks but now I have an error saying
    "Cannot convert 'boolean' to 'UnityEngine.Camera" I don't know what that means either (Im really new to scripting so sorry for being not smart).
     
  5. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    I assume that is a side effect of the improper syntax used in your code.

    For example, you're using functionStart when it should be function Start (function FunctionName). Same for functionUpdate.
    You're also using elseif when it should be else if.
     
  6. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    Sorry, for some reason it came up like that when I pasted it (I have it like you said in the actual script). So I still have no clue what to do
     
  7. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    I copied and pasted and it compiled fine. What line has the problem?
     
  8. Hippiecode

    Hippiecode

    Joined:
    Feb 13, 2012
    Posts:
    110
    Script is perfectly fine which type error is occured i couldn,t get any error like u said.......
     
  9. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    The error is on (17,31)
     
  10. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Post your new version of the script (using code tags).
     
  11. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    1
    Code (JavaScript):
    1. var LeftCamera : Camera;
    2. 2 var RightCamera : Camera;
    3. 3
    4. 4 function Start () {
    5. 5    LeftCamera.enabled = true;
    6. 6   RightCamera.enabled = false;
    7. 7 }
    8. 8
    9. 9 function Update () {
    10. 10     if (Input.GetButtonDown ("SwitchShoulders"))
    11. 11        if( LeftCamera.enabled == true){
    12. 12          RightCamera.enabled = true;
    13. 13         LeftCamera.enabled = false;
    14. 14     }
    15. 15    else if (RightCamera.enabled == true){
    16. 16        LeftCamera.enabled = true;
    17. 17        RightCamera = false;
    18. 18        
    19. 19        
    20. 20          }
    21. 21     }
    22.  
    23.    
    24.  
    Sorry for the crappy numbers, it didnt add on so I had to type them in
     
  12. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    here's an easier to read version

    Code (JavaScript):
    1. var LeftCamera : Camera;
    2. var RightCamera : Camera;
    3.  
    4. function Start () {
    5.     LeftCamera.enabled = true;
    6.     RightCamera.enabled = false;
    7. }
    8.  
    9. function Update () {
    10.     if (Input.GetButtonDown ("SwitchShoulders"))
    11.         if( LeftCamera.enabled == true){
    12.          RightCamera.enabled = true;
    13.          LeftCamera.enabled = false;
    14.     }
    15.     else if (RightCamera.enabled == true){
    16.         LeftCamera.enabled = true;
    17.         RightCamera = false;
    18.        
    19.        
    20.          }
    21.     }
    22.  
    23.    
    24.  
     
  13. TwistOfFat3

    TwistOfFat3

    Joined:
    Oct 10, 2014
    Posts:
    7
    Add a { at the end of line 10, you're missing one there.
     
  14. Dameon_

    Dameon_

    Joined:
    Apr 11, 2014
    Posts:
    542
    No he's not. It is perfectly valid as written.

    The problem is on line 17. See if you can spot it yourself. One of these things is not like the other.
     
  15. TwistOfFat3

    TwistOfFat3

    Joined:
    Oct 10, 2014
    Posts:
    7
    Whoops, indeed. Oversight on my part due to the formatting :\
     
  16. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    Ok, so I fixed the script finally, but it it asks me to select what Left Camera is and what Right Camera is here's what I get: Screenshot (39).png on the right. But when I go to select which camera is which it shows me this and says I cant add anything Screenshot (41).png How do I add my cameras to this assets page?
     
  17. TwistOfFat3

    TwistOfFat3

    Joined:
    Oct 10, 2014
    Posts:
    7
    Drag & Drop them from the Hierachy on the left onto the Camera fields.
     
  18. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    I
    It won't let me
     
  19. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Assign that script to a GameObject, then drag and drop the Cameras onto it with that GameObject selected. Right now your script is not in the scene, so it doesn't know anything about your scene (like what cameras you have).
     
  20. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    thank you so much, I finally got it to work!
    I just have one question. How do I add smoothing so that the camera will have a little movement (like resident evil 6)?