Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need help with scripting

Discussion in 'Scripting' started by cCheerSs, Jan 23, 2014.

  1. cCheerSs

    cCheerSs

    Joined:
    Jan 23, 2014
    Posts:
    4
    Hello. I'm new at Unity 3D and I try to make some game by watchinng tutorials for begginers. And now I have error on one of the lines, I dont know how to explain that and hot to fix that. Please help me if you can :).


    Sorry for my bad english



    There is a photos of my script and Unity error.




     
  2. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    389
    there is a } in the requirecomponent line that should not be there
     
  3. cCheerSs

    cCheerSs

    Joined:
    Jan 23, 2014
    Posts:
    4
    I deleted it, but it still writing ''error CS8025: Parsing Error'' ... :/
     
  4. joni-giuro

    joni-giuro

    Joined:
    Nov 21, 2013
    Posts:
    435
    can you paste your whole script? I think you forgot to close a bracket or something like that
     
  5. cCheerSs

    cCheerSs

    Joined:
    Jan 23, 2014
    Posts:
    4
    using UnityEngine;
    using System.Collections;

    [RequireComponent (typeof(CharacterController))]
    public class FirstPersonController : MonoBehaviour {

    public float movementspeed = 5.0f;
    public float sidespeed = 3.0f;
    public float UpDownRange = 60.0f;
    public float mousespeed = 2.0f;
    public float jumpSpeed = 2.0f;

    float verticalRotation = 0;

    float VerticalVelocity = 0;

    CharacterController characterController;

    // Use this for initialization
    void Start () {

    Screen.lockCursor = true;
    CharacterController characterController = GetComponent <CharacterController> ();
    Debug.Log(characterController);


    }

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


    //rotation

    float rotLeftRight = Input.GetAxis ("Mouse X") * mousespeed;
    transform.Rotate (0, rotLeftRight, 0);

    verticalRotation -= Input.GetAxis ("Mouse Y") * mousespeed;
    verticalRotation = Mathf.Clamp (verticalRotation, -UpDownRange, UpDownRange);
    Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0);

    //movement


    float forwardSpeed = Input.GetAxis("Vertical") * movementspeed;
    float sideSpeed = Input.GetAxis("Horizontal") * sidespeed;

    VerticalVelocity += Physics.gravity.y * Time.deltaTime;

    if( characterController.isGrounded Input.GetButtonDown("Jump") ) {
    VerticalVelocity = jumpSpeed;

    }


    Vector3 speed = new Vector3 ( sideSpeed, VerticalVelocity, forwardSpeed );


    speed = transform.rotation * speed;


    characterController.Move( speed * Time.deltaTime );
    }
    }



    Maybe you will find something here? :).
     
  6. softwizz

    softwizz

    Joined:
    Mar 12, 2011
    Posts:
    793
    I didnt get any parsing error but CharacterController characterController was being defined twice so I just removed one and the code below works
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.      
    4. [RequireComponent (typeof(CharacterController))]
    5. public class FirstPersonController : MonoBehaviour
    6. {
    7.     public float movementspeed = 5.0f;
    8.     public float sidespeed = 3.0f;
    9.     public float UpDownRange = 60.0f;
    10.     public float mousespeed = 2.0f;
    11.     public float jumpSpeed = 2.0f;
    12.     float verticalRotation = 0;
    13.     float VerticalVelocity = 0;
    14.     CharacterController characterController;
    15.    
    16.     // Use this for initialization
    17.     void Start ()
    18.     {
    19.         Screen.lockCursor = true;
    20.         characterController = GetComponent <CharacterController> ();
    21.         Debug.Log(characterController);
    22.     }
    23.    
    24.     // Update is called once per frame
    25.     void Update ()
    26.     {
    27.         //rotation
    28.         float rotLeftRight = Input.GetAxis ("Mouse X") * mousespeed;
    29.         transform.Rotate (0, rotLeftRight, 0);
    30.         verticalRotation -= Input.GetAxis ("Mouse Y") * mousespeed;
    31.         verticalRotation = Mathf.Clamp (verticalRotation, -UpDownRange, UpDownRange);
    32.         Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0);
    33.        
    34.         //movement
    35.         float forwardSpeed = Input.GetAxis("Vertical") * movementspeed;
    36.         float sideSpeed = Input.GetAxis("Horizontal") * sidespeed;
    37.         VerticalVelocity += Physics.gravity.y * Time.deltaTime;
    38.         if(characterController.isGrounded  Input.GetButtonDown("Jump"))
    39.         {
    40.             VerticalVelocity = jumpSpeed;
    41.         }
    42.         Vector3 speed = new Vector3 ( sideSpeed, VerticalVelocity, forwardSpeed );
    43.         speed = transform.rotation * speed;
    44.         characterController.Move( speed * Time.deltaTime );
    45.     }
    46.  
     
    Last edited: Jan 23, 2014