Search Unity

need help moving sprites

Discussion in 'Getting Started' started by Melodee, Mar 16, 2016.

  1. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    ok, i have tried a few tutorials (like 20 or something) for a 2D game and the scripts they used didn't help since im unable to make my own script (i keep getting errors). first i want to be able to make my character move atleast, and then make the sprite move (like a gif, the sprite changes when you push the move button. im using this script:

    using UnityEngine;
    using System.Collections;

    public class MovingPlayer : MonoBehaviour {

    public float moveSpeed;


    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    if (Input.GetKey(KeyCode.UpArrow))

    {
    transform.Translate(new Vector3(-moveSpeed, 0, 0)) * Time.deltaTime)
    }

    if (Input.GetKey(KeyCode.DownArrow))
    {
    transform.Translate(new Vector3(-moveSpeed, 0, 0)) * Time.deltaTime)
    }

    if (Input.GetKey(KeyCode.LeftArrow))
    {
    transform.Translate(new Vector3(0, -moveSpeed, 0)) * Time.deltaTime)
    }

    if (Input.GetKey(KeyCode.RightArrow))
    {
    transform.Translate(new Vector3(0, -moveSpeed, 0)) * Time.deltaTime)
    }

    }
    }
     
  2. Foggy-Noggin

    Foggy-Noggin

    Joined:
    Mar 6, 2016
    Posts:
    51
    Well for starters, try a semicolon after your transform.Translate statements. Brush up on your C#, if you aren't an experienced programmer focus on learning C#.
     
  3. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    i dun wanna learn programming i just want to make my character move for my portfolio t-t i wanna do gameart not gamedeveloping XDD
    can you explain why i am getting errors instead of making me learn something?
     
  4. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    oh and also, i tried putting a semicolon in it and i even get more errors o-o thankyou for replying tho.
     
  5. Foggy-Noggin

    Foggy-Noggin

    Joined:
    Mar 6, 2016
    Posts:
    51
    That was the solution, or at least one of them. If your going to use C#, your going to have to learn C#, I'm not saying become a C programmer, but clearly if you have to write a script, it must be syntactically correct, and you must know some basics.
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    No, we can't explain why you're getting errors without making you learn something. You would be unable to understand the explanations. @Foggy Noggin is quite right; you're missing semicolons at the end of your statements.

    If you're really unwilling to learn any programming, then you should quit trying to make scripts. Stick to things you can find among the standard assets or Asset Store, or find a friend who enjoys programming to help you out. It's a deep skill, I'm afraid — just like art, it takes some dedication and quite a bit of practice to get any good at it.

    On the other hand, I believe you can learn it if you try... and you may be surprised how much fun it is!
     
  7. Foggy-Noggin

    Foggy-Noggin

    Joined:
    Mar 6, 2016
    Posts:
    51
    Ok, now look in the console in the Unity editor, it will tell you the error(s), which you may not understand, but it will also give you the line number and position of each error. Fix that line and try again. You may get another error, fix that line and so on. At some point you will run out of error and it will compile. Make sure you save the changes in the script .
     
    JoeStrout likes this.
  8. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    well someone once told me " ; " is like a period to a sentence o-o im not sure what semicolons mean but i gave it a shot XDD anyway thanks, i will google wha it means.
     
  9. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    the errors are saying:

    ; expected (line 20)
    } expected (line 20)
    ; expected (line 25)
    } expected (line 30)
    ; expected (line 30)
    } expected (line 35)
    ; expected (line 35)
    Operator '*' cannot be applied to operands of type 'void' and 'float' (line 20, 25, 30 and 35)

    and my script is:

    using UnityEngine;
    using System.Collections;

    public class MovingPlayer : MonoBehaviour {

    public float moveSpeed;


    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    if (Input.GetKey(KeyCode.UpArrow))

    {
    transform.Translate(new Vector3(-moveSpeed, 0, 0)) * Time.deltaTime);
    }

    if (Input.GetKey(KeyCode.DownArrow))
    {
    transform.Translate(new Vector3(-moveSpeed, 0, 0)) * Time.deltaTime);
    }

    if (Input.GetKey(KeyCode.LeftArrow))
    {
    transform.Translate(new Vector3(0, -moveSpeed, 0)) * Time.deltaTime);
    }

    if (Input.GetKey(KeyCode.RightArrow))
    {
    transform.Translate(new Vector3(0, -moveSpeed, 0)) * Time.deltaTime);
    }

    }
    }


    i already put the semicolons in it so i have no clue what to do now. it'd be awesome if you gave me a hint.
     
  10. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Now the problem is that your parentheses don't match up. Just like in school, if you wrote "x = ((y+z)*3)/2)" on your paper, you'd get points off because you have three ')' close parentheses but only two '(' open parentheses. So it just doesn't make sense.

    In your case, I think you just need to remove one of the doubled ')' in the middle of each Translate line, e.g.:

    Code (csharp):
    1. transform.Translate(new Vector3(-moveSpeed, 0, 0)) * Time.deltaTime);
    should be

    Code (csharp):
    1. transform.Translate(new Vector3(-moveSpeed, 0, 0) * Time.deltaTime);
    Whenever you've got an error on a line, and you've already checked the semicolon, counting parentheses is a good next step. :)
     
  11. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56

    OHMYGOD I GOT IT FINALLY. 0 ERRORS. okay how to try the game? it'd be awesome if you could help me out tommorow when i continue making the game.
     
  12. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Erm... how have you done 20 or so tutorials, but you don't know how to try a game? Is there some particular difficulty in your game that just clicking the Play button doesn't do it?
     
  13. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    ye i tried clicking the button but nothing happend so i thought i clicked the wrong button.
     
  14. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    aaaand the play button still doesnt work.
     
  15. maquis

    maquis

    Joined:
    Feb 7, 2016
    Posts:
    61
    Umm... what happens when you click the play button? Did you put your scripts on the objects?

    We arent mind readers, and we arent going to do your project for you. What are you doing differently from the tutorials you watched? When you did the tutorials, did you just watch, or did you follow along with the tutorials step by step to get the same results that they did? Following along helps for a few reasons:
    1) you will remember what you learned better
    2) you will have to debug some problems when things dont match up with what the tutorial shows, so you will learn more of the system
    3) you will come out with a reference you can save that you can refer to in the future

    Honestly, I am not sure what you are doing here if you dont want to learn how to program. It almost sounds like you are taking some sort of class, but dont want to learn the material or do the work, and want the forum to do it for you. Whether or not that is the case, though, I recommend that you really think seriously about why you are here, why you are doing this project, and what uou are hoping to gain from this.