Search Unity

Simple Move script Help

Discussion in 'Community Learning & Teaching' started by WeirdDeveloping, Nov 18, 2015.

  1. WeirdDeveloping

    WeirdDeveloping

    Joined:
    Nov 17, 2015
    Posts:
    3
    Hi! I Have just got Unity and have experience of programming and starting to build a game
    i am working on a movement script but it dosent work
    Here is the script

    usingUnityEngine;
    usingSystem.Collections;

    publicclassmove : MonoBehaviour {

    //Usethisforinitialization
    voidStart () {

    }

    //Updateiscalledonceperframe
    voidUpdate () {
    if (Input.GetKey ("w")) {

    transform.Translate((Vector3.forward) * 100 * Time.deltaTime)
    }
    }
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    A couple of things.

    First, can you use code tags when posting code in this forum?
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/

    Looking at this code, it's not well formatted, so make sure when using your code tags, you also have well formatted code with no unnecessary code:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class move : MonoBehaviour {
    5.  
    6.      voidUpdate () {
    7.           if (Input.GetKey ("w")) {
    8.                transform.Translate((Vector3.forward) * 100 * Time.deltaTime)
    9.           }
    10.      }
    11. // missing bracket? copy and paste issue with snippet? parsing errors in the console?
    So, code issues out of the way: What's not working about this script?

    Is it attached to a GameObject in the scene?

    Do you have any errors in the console?

    (This code snippet is missing a last bracket, but this could be a copy and paste issue...)
     
  3. WeirdDeveloping

    WeirdDeveloping

    Joined:
    Nov 17, 2015
    Posts:
    3
    It says "All Compiler Errors should be fixed before entering play mode"
    And when i don't get the error, The Character won't move
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Do you currently have an error in the console with that script?

    (and)

    Are you missing the last brace/bracket in your code?
     
  5. WeirdDeveloping

    WeirdDeveloping

    Joined:
    Nov 17, 2015
    Posts:
    3
    Yes, i do get and error
    here is the script

    usingUnityEngine;
    usingSystem.Collections;

    publicclassmove : MonoBehaviour {
    voidStart () {
    }
    voidUpdate () {
    if (Input.GetKey ("w")) {
    transform.Translate((Vector3.forward) * 100 * Time.deltaTime)
    }
    }
    }


    As you can see there is no missing bracket
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please use code tags as stated above.
     
  7. subbu5280

    subbu5280

    Joined:
    Oct 1, 2015
    Posts:
    5
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Move : MonoBehaviour {
    5.         void Start () {
    6.         }
    7.         void Update () {
    8.             if (Input.GetKey ("w")) {
    9.             transform.Translate((Vector3.forward) * 100 * Time.deltaTime);
    10.             }
    11.         }
    12. }
    WeirdDeveloping
    you missed semicolon end of the statement that's why its giving error.
    transform.Translate((Vector3.forward) * 100 * Time.deltaTime)
    it was before like this.
     
    Last edited: Nov 30, 2015
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    What are the errors you are getting in your code? (You can copy and paste the entire error from the lower window in the console panel when you have clicked on the error you want to copy.)