Search Unity

I need help with some coding

Discussion in 'Scripting' started by TheOrangeNinja2245, Jul 19, 2019.

  1. TheOrangeNinja2245

    TheOrangeNinja2245

    Joined:
    Nov 24, 2018
    Posts:
    5
    i am new with coding so i need some help
    when unity compiles the script it says that it needs ';' at the ends of lines 41 and 46

    If(Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f) <---- line 41
    {
    myRigidBody.Velocity = new Vector2(0f, myRigidbody.velocity.y);
    }

    If(Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f) <----- line 46
    {
    myRigidBody.Velocity = new Vector2(myRigidbody.velocity.x, 0f);
    }

    when i add it it then screws up the if statement
    please help!
    ps. i use notepad as i cant use visual studio (ik its sad but whatever rlly)
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,093
    This syntax looks correct something must be missing on previous lines, check yourselft or post full script. Btw, are you using capital I for If or it's just a typo or autocorrection?
     
  3. TheOrangeNinja2245

    TheOrangeNinja2245

    Joined:
    Nov 24, 2018
    Posts:
    5
    nvm i changed it to lower case and that fixed it
    Thanks!
     
  4. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,757
    What do you mean you cant use visual studio? Why? Visual studio code is free and small, runs on literally potato pcs. Can you explain why you cant use visual studio?
     
  5. TheOrangeNinja2245

    TheOrangeNinja2245

    Joined:
    Nov 24, 2018
    Posts:
    5
    why do you need to know?
     
  6. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,757
    Because I am trying to help you. Didnt realise it was going to be sensitive information.

    If you cant answer why your not using an IDE, then good luck getting any useful answers out of anyone here :)
     
    Lysander and SparrowsNest like this.
  7. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    154
    Because not using a decent IDE makes the job of programming much more tedious than it needs to be.
     
    Lysander and GameDevCouple_I like this.
  8. Lysander

    Lysander

    Joined:
    Feb 24, 2013
    Posts:
    1,648
    Use code tags as shown in the stickied thread at the top of every forum here, and please don't waste people's time being combative about really simple questions or they'll choose not to help you. There's zero reason not to be using an IDE of some sort, no matter what OS or system specs you have- you can even use a free web-based IDE without installing it locally.

    The irony here is that the code tags will do a better job of displaying your code than your "IDE" does...
     
    GameDevCouple_I likes this.
  9. TheOrangeNinja2245

    TheOrangeNinja2245

    Joined:
    Nov 24, 2018
    Posts:
    5
    i just realised i signed in with the wrong acc (i dont have access on one)
    im stoopid sometimes
     
  10. Starmind01

    Starmind01

    Joined:
    May 23, 2019
    Posts:
    11
    Try this
    Code (CSharp):
    1. If(Input.GetAxisRaw("Horizontal") < 0.5f && (Input.GetAxisRaw("Horizontal") > -0.5f))
    2. {
    3.    myRigidBody.Velocity = new Vector2(0f, myRigidbody.velocity.y);
    4. }
    5.  
    6. If(Input.GetAxisRaw("Vertical") < 0.5f && (Input.GetAxisRaw("Vertical") > -0.5f))
    7. {
    8.    myRigidBody.Velocity = new Vector2(myRigidbody.velocity.x, 0f);
    9. }
     
  11. Starmind01

    Starmind01

    Joined:
    May 23, 2019
    Posts:
    11
    I guess I should explain why your code is not working. On your if statements you forgot the ( on the second Input and at the end you needed another ) to finish. If you had been using visual studio it would have red lined you and let you know there was a mistake.
    Now if you don't want to use visual studio, then you could use notepad++. I use it from time to time for quick edits with out having unity even opened. It will let you know if you are making a mistake in C#, but not in unity syntax.
    Hope this helps.
     
    GameDevCouple_I likes this.
  12. TheOrangeNinja2245

    TheOrangeNinja2245

    Joined:
    Nov 24, 2018
    Posts:
    5
    also is there a way to increase the characters horizontal speed in this script?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7. public float moveSpeed;
    8.  
    9. private Animator anim;
    10. private Rigidbody2D myRb;
    11.  
    12. private bool playerMoving;
    13. private Vector2 LastMove;
    14.  
    15. void Start()
    16. {
    17. anim = GetComponent<Animator>();
    18. myRb = GetComponent<Rigidbody2D>();
    19. }
    20.  
    21. void Update()
    22. {
    23. playerMoving = false;
    24.  
    25. if(Input.GetAxisRaw ("Horizontal") > 0.5f || Input.GetAxisRaw ("Horizontal") < -0.5f)
    26. {
    27. //transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
    28. myRb.velocity = new Vector2(Input.GetAxisRaw("Horizontal"), myRb.velocity.y * moveSpeed);
    29. playerMoving = true;
    30. LastMove = new Vector2(Input.GetAxisRaw ("Horizontal"), 0f);
    31. }
    32.  
    33. if(Input.GetAxisRaw ("Vertical") > 0.5f || Input.GetAxisRaw ("Vertical") < -0.5f)
    34. {
    35. //transform.Translate (new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
    36. myRb.velocity = new Vector2(myRb.velocity.x, Input.GetAxisRaw("Vertical") * moveSpeed / 2);
    37. playerMoving = true;
    38. LastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
    39. }
    40.  
    41. if(Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
    42. {
    43. myRb.velocity = new Vector2(0f, myRb.velocity.y);
    44. }
    45.  
    46. if(Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f)
    47. {
    48. myRb.velocity = new Vector2(myRb.velocity.x, 0f);
    49. }
    50.  
    51. anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
    52. anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
    53. anim.SetBool("PlayerMoving", playerMoving);
    54. anim.SetFloat("LastMoveX", LastMove.x);
    55. anim.SetFloat("LastMoveY", LastMove.y);
    56. }
    57. }
    58.  
    thanks!