Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do I fix these errors?

Discussion in 'Scripting' started by Treasureman, Dec 27, 2014.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    I have a script that's supposed to align the player with the camera whenever you move. here's my script.
    Code (JavaScript):
    1. //Return direction align with Camera
    2. Vector3 targetDirection
    3. {
    4. get
    5. {
    6. Vector3; cameraForward = mainCamera.TransformDirection(Vector3.forward);
    7. cameraForward.y = 0; //set to 0 because of camera rotation on the X axis
    8.  
    9. //get the right-facing direction of the camera
    10. Vector3; cameraRight = mainCamera.TransformDirection(Vector3.right);
    11.  
    12. //determine the direction the player will face based on input and the camera's right and forward directions
    13. return Input.GetAxis("Horizontal") * cameraRight + Input.GetAxis("Vertical") * cameraForward;
    14. }
    15. }
    16.  
    17. //This method needs to run on Update
    18. void RotateWhileMoving()
    19. {
    20. if(speed > 0.5f)
    21. {
    22. //normalize the direction the player should face
    23. Vector3; lookDirection = targetDirection.normalized;
    24.  
    25. //rotate the player to face the correct direction ONLY if there is any player input
    26. if (lookDirection != Vector3.zero)
    27. {
    28. newRotation = Quaternion.LookRotation(lookDirection);
    29.  
    30. transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, 4.5f * Time.deltaTime);
    31. }
    32. }
    33. }
    But I keep getting these errors
    Screenshot (60).png
    How do I fix these?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    You keep writing "Vector3;" instead of "Vector3". Semicolons can only be used at the end of statements.

    --Eric
     
  3. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    but before i got an error saying i needed to add them saying "expecting semicolon at end (2,8)"
     
  4. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    If you're doing javascript I believe what you want is var varName : Vector3