Search Unity

i cant seem to get this script to work, i just shows erors, cood anyontake a look at it and see why?

Discussion in 'Scripting' started by ncoy01, May 29, 2015.

  1. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    I have windows 8.1, and I use the free unity 5 if that maybe has something to do with it. I am currently trying to make the ball rolling game thing. im trying to learn how to make easy games to show my friends.
    here it is.
    using UnityEngine;
    using System.Collections;
    public class playercontroler : MonoBehaviour {
    private Rigidbody rb;

    void Start
    {
    rb = GetComponent<Rigidbody>();
    }

    void fixedupdate
    {
    float moveHorizontal = Input.GetAxis {"Horizontal"};
    float moveVertical = Input.GetAxis ("Vertical"};

    Vector3 movemennt = new Vector3 (moveHorazontal, 0.0f, moveVertical};
    }

    }
     
  2. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    389
    First, a few guidelines. When you post code, please use code tags. When you ask about errors in a script it always helps to post the error itself as well as the code.

    Now, with that out of the way, Input.GetAxis should not be followed by { but by (

    Code (csharp):
    1. Input.GetAxis ("Horizontal");
     
    NomadKing likes this.
  3. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    You have the same error that @dterbeest mentioned on your other GetAxis call, and your Vector assignment has a spelling mistake (Horizontal) as well as the same bracket issue. Function calls use round brackets not curly ones.

    Your function declarations also missing a set of brackets, like:
    Code (csharp):
    1. void Start()
     
    ncoy01 likes this.
  4. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    how do you use code tags
     
    NomadKing likes this.
  5. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    You can either select 'Code' after clicking the 'Insert' option on the toolbar above the reply box, or you can put your code between [code ] and [/code ] without the spaces.
     
  6. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    thanks, that got rid of some of the errors
     
  7. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. using System.Collections;
    4.  
    5. public class playercontroler : MonoBehaviour {
    6.  
    7.     private Rigidbody rb;
    8.  
    9.  
    10.  
    11.  
    12.     void Start()
    13.      
    14.     {
    15.      
    16.         rb = GetComponent<Rigidbody>();
    17.      
    18.     }
    19.  
    20.  
    21.  
    22.  
    23.     void fixedupdate
    24.      
    25.     {
    26.      
    27.         float moveHorizontal = Input.GetAxis ("Horizontal");
    28.      
    29.         float moveVertical = Input.GetAxis ("Vertical");
    30.                                          
    31.                                          
    32.                                          
    33.                                          
    34.                                             Vector3 movemennt = new Vector3 {moveHorazontal, 0.0f, moveVertical};
    35.                                        
    36.                                          }
     
  8. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    hop this is right
     
  9. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    Almost there, you still had a few bracket issues near the end ;)

    This should be correct:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playercontroler : MonoBehaviour {
    5.    
    6.     private Rigidbody rb;
    7.  
    8.     void Start()
    9.     {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     void FixedUpdate()  
    14.     {
    15.         float moveHorizontal = Input.GetAxis ("Horizontal");
    16.         float moveVertical = Input.GetAxis ("Vertical");
    17.        
    18.         Vector3 movemennt = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    19.     }
    20. }
     
  10. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playercontroler : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     void Start()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.  
    15.     void FixedUpdate()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movemennt = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce (movement * speed);
    23.     }
    24.  
     
  11. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    I added rb.addforce (movement * speed); but when I play it the screen says all compliyer errors have to be fixed?
     
  12. Deleted User

    Deleted User

    Guest

    Unity should get rid of the string argument for GetAxis and make it an enum.
     
  13. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Input Manager lets you create unique axis names so that wouldn't work. Unless Unity were to compile an enum set based on the string names.
     
    Deleted User likes this.
  14. Deleted User

    Deleted User

    Guest

    Oh I didn't know that. I've never used it before. Guess I just put my foot in my mouth.