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. Dismiss Notice

how to fix my error

Discussion in 'Scripting' started by pinkpenguindev, Sep 4, 2020.

?

do you like my pic

This poll will close on Sep 4, 2030 at 1:46 AM.
  1. yes

    2 vote(s)
    100.0%
  2. no

    0 vote(s)
    0.0%
  1. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    using UnityEngine;

    public class bird : MonoBehaviour
    {

    private void OnMouseDown()
    {
    GetComponent<SpriteRenderer>().color = Color.green:
    }


    }
    i get Assets\bird.cs(9,55): error CS1002: ; expected
    and Assets\bird.cs(9,55): error CS1513: } expected
     
  2. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    You need to pay close attention to what you are typing. C# has no tolerance for typos. Look carefully at the line where you are getting the error message (line 9) and you will notice you are incorrectly using a colon : instead of a semicolon ;

    Give your threads better titles. All "how to fix my error" tells us is that you have an error. Try adding the error to the title to make it more useful.
     
    adehm likes this.
  3. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
  4. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    i have some more error
    Assets\bird.cs(17,25): error CS0619: 'Component.camera' is obsolete: 'Property camera has been deprecated. Use GetComponent<Camera>() instead. (UnityUpgradable)'

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class bird : MonoBehaviour
    4. {
    5. private  void  OnMouseDown()
    6. {
    7.    GetComponent<SpriteRenderer>().color = Color.green;  
    8. }
    9. private  void  OnMouseUp()
    10. {
    11.    GetComponent<SpriteRenderer>().color = Color.white;  
    12. }
    13. private  void  OnMouseDrag()
    14. {
    15.   Vector3 newPosition = camera.main.ScreenToWorldPoint(Input.mousePosition);
    16.   transform.position = newPosition;
    17. }
    18.  
    19.  
    20. }
    21.  
     
  5. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
  6. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    It's another capitalization issue.

    "Camera", not "camera"
     
  7. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    You posted the same question to 2 different threads, and then bumped one of those threads, all in less than 30 minutes.

    That's really spammy. Please cut it out.
     
    eses likes this.
  8. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
  9. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    im new and bob help me fix it soo
     
  10. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    ok
     
  11. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    help
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class bird : MonoBehaviour
    4. {
    5. private  void  OnMouseDown()
    6. {
    7.    GetComponent<SpriteRenderer>().color = Color.green;  
    8. }
    9. private  void  OnMouseUp()
    10. {
    11.    GetComponent<SpriteRenderer>().color = Color.white;  
    12. }
    13. private  void  OnMouseDrag()
    14. {
    15.   Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    16.   transform.position = new Vector3(newPosition.x, newPosition.y);
    17.  
    18.  
    19. }
    20.  
    i get Assets\bird.cs(21,2): error CS1513: } expected
     
  12. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Have you made any attempt to fix this yourself in the 4 minutes between your last post and this one?

    An important part of being a developer is being able to solve problems on your own, especially common and trivial ones. Try googling the error message for a bit and seeing if you can fix it yourself.

    Look at this new bird script and the old one. You fixed "Camera" properly, but you also changed something else by accident.
     
    eses likes this.
  13. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    i did and no one works
     
  14. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    yes but it did not work
     
  15. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Have you checked line 17 for any accidental changed between the old and new bird script?
     
  16. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    yes but it is the same
     
  17. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    ... No, it's not.

    Your original bird script (with the camera bug) had a } on line 17, whereas your new one (with the Camera bug fixed) doesn't

    Put that } back.
     
  18. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    it dose not mater i still get the same error
     
  19. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Can you post the script as it currently is? It should not have that error anymore.
     
  20. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    using UnityEngine;

    public class bird : MonoBehaviour
    {

    private void OnMouseDown()
    {
    GetComponent<SpriteRenderer>().color = Color.green;
    }
    private void OnMouseUp()
    {
    GetComponent<SpriteRenderer>().color = Color.white;
    }
    private void OnMouseDrag()
    {
    Vector3 newPosition = camera.main.ScreenToWorldPoint(Input.mousePosition);
    transform.position = new Vector3(newPosition.x, newPosition.y);


    }
     
  21. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    You didn't put the } where I told you to...

    You need to match opening {'s with closing }'s

    You have not done that, you have a { for the class, and a { for the OnMouseDrag function.

    You have a } for the OnMouseDrag function, but no } for the class.
     
  22. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    but where show me
     
  23. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Add the } to the end of your script to close off the class.
     
  24. UnityMaru

    UnityMaru

    Community Engagement Manager Unity Technologies

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    @pinkpenguindev we'll need you to really up the quality of your posts and take the time to read what is explained, and give that same effort back. Threads are not for direct 1-1 help in this manner.
     
    bobisgod234, Vryken and eses like this.
  25. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    Assets\bird.cs(2,19): error CS0234: The type or namespace name 'SceneMangement' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneMangement;
    3.  
    4. public class bird : MonoBehaviour
    5. {
    6.  
    7. Vector3 _initialPosition;
    8.  
    9. private  void Awake()
    10. {
    11.   _initialPosition = transform.position;
    12. }
    13.  
    14. private  void update()
    15. {
    16.   if (transform.position.y > 10);
    17.      SceneManager.loadScene(SceneManager.GetActiveScene().name);
    18.  
    19. }
    20.  
    21.  
    22. private  void  OnMouseDown()
    23. {
    24.    GetComponent<SpriteRenderer>().color = Color.green;  
    25. }
    26. private  void  OnMouseUp()
    27. {
    28.    GetComponent<SpriteRenderer>().color = Color.white;
    29.    Vector2 directionToInitialPosition = _initialPosition - transform.position;
    30.    GetComponent<Rigidbody2D>().AddForce(directionToInitialPosition * 100);
    31.     GetComponent<Rigidbody2D>().gravityScale = 1;  
    32. }
    33. private  void  OnMouseDrag()
    34. {
    35.   Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    36.   transform.position = new Vector3(newPosition.x, newPosition.y);
    37. }
    38.  
    39. }
    40.  
     
  26. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    258
    Again just a typo on your side...

    It's called SceneManagement, not SceneMangement.


    Edit:
    If you would use the documentation you would easily see where the SceneManager class is located. (It's written right at the top, below SceneManager)
    Thus a question like this won't even come up.