Search Unity

I am new and don't know how to fix this code

Discussion in 'Scripting' started by Seechee, Sep 25, 2020.

  1. Seechee

    Seechee

    Joined:
    Sep 25, 2020
    Posts:
    8
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Collections.Specialized;
    4. using System.Security.Cryptography;
    5. using System.Threading;
    6. using UnityEngine;
    7.  
    8. public class SwingingArm : MonoBehaviour
    9. {
    10.     //GameObjects
    11.     public GameObject LeftHand;
    12.     public GameObject RightHand;
    13.     public GameObject CenterEyeCamera;
    14.     public GameObject ForwardDirection;
    15.  
    16.     //Vector3 positions
    17.     private Vector3 PositionsPreviousFrameLeftHand;
    18.     private Vector3 PositionPreviousFrameRightHand;
    19.     private Vector3 PlayerPositionThisFrame;
    20.     private Vector3 PlayerPositionPreviousFrame;
    21.     private Vector3 PositionThisFrameLeftHand;
    22.     private Vector3 PositionThisFrameRightHand;
    23.  
    24.     //Speed
    25.     public float Speed - 70;
    26.     private float HandSpeed;
    27.  
    28.     // Start is called before the first frame update
    29.     void Start()
    30.     {
    31.         //Set original Previous frame positions at start up
    32.         PlayerPositionPreviousFrame - transform.position;
    33.         PositionsPreviousFrameLeftHand - LeftHand.transform.position;
    34.         PositionPreviousFrameRightHand - RightHand.transform.position;
    35.     }
    36.  
    37.     // Update is called once per frame
    38.     void Update()
    39.     {
    40.         //Get the forward direction from the center eye camera and set it to the forward direction object
    41.         float yRotation -CenterEyeCamera.transform.eulerAngles.y;
    42.         ForwardDirection.transform.eulerAngles - new Vector3(0, yRotation, 0);
    43.  
    44.         //Get current positions of hands
    45.         PositionThisFrameLeftHand - LeftHand.transform.position;
    46.         PositionThisFrameRightHand - RightHand.transform.position;
    47.         //position off Player
    48.         PlayerPositionThisFrame - transform.position;
    49.  
    50.         //Get distance the hands and player has moved since last frame
    51.         var playerDistanceMoved -Vector3.Distance(PlayerPositionThisFrame, PlayerPositionPreviousFrame);
    52.         var leftHandDistanceMoved -Vector3.Distance(PositionsPreviousFrameLeftHand, PositionThisFrameLeftHand);
    53.         var rightHandDistanceMoved -Vector3.distance(PositionPreviousFrameRightHand, PositionThisFrameRightHand);
    54.  
    55.         //Add them up to get the handspeed from the user minus the movement of the player to neglect the movement of the player from The equation
    56.         HandSpeed - ((leftHandDistanceMoved - playerDistanceMoved) + (rightHandDistanceMoved - playerDistanceMoved));
    57.  
    58.  
    59.         if (Time.timeSinceLevelLoad > 1f)
    60.             transform.position + -ForwardDirection.transform.forward * Speed * Timeout.deltaTime;
    61.  
    62.  
    63.  
    64.         //Set previous positions of hands for the next frame
    65.         PositionThisFrameLeftHand - PositionThisFrameRightHand;
    66.         //Set player position previous frame
    67.         PlayerPositionPreviousFrame - PlayerPositionThisFrame;
    68.  
    69.  
    70.     }
    71. }
    72.  
     
  2. Seechee

    Seechee

    Joined:
    Sep 25, 2020
    Posts:
    8
    Help would be largely appreciated. error codes are

    Assets\SwingingArm.cs(25,24): error CS1003: Syntax error, ',' expected
    Assets\SwingingArm.cs(41,25): error CS1002: ; expected
    Assets\SwingingArm.cs(51,33): error CS1002: ; expected
    Assets\SwingingArm.cs(52,35): error CS1002: ; expected
    Assets\SwingingArm.cs(53,36): error CS1002: ; expected

    Thanks in advanced
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    You seem to be using a minus sign - instead of an = sign on all of those lines.

    Probably the same problem on line 56 and others.
     
  4. Seechee

    Seechee

    Joined:
    Sep 25, 2020
    Posts:
    8
    ok i'll go through it thanks
     
  5. Seechee

    Seechee

    Joined:
    Sep 25, 2020
    Posts:
    8
    haha the tutorial is so low quality that the top line on the = is missing cause of compression lol
     
  6. Seechee

    Seechee

    Joined:
    Sep 25, 2020
    Posts:
    8
    Having more trouble... error code
    Assets\SwingingArm.cs(60,34): error CS1525: Invalid expression term '='
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Collections.Specialized;
    4. using System.Security.Cryptography;
    5. using System.Threading;
    6. using UnityEngine;
    7.  
    8. public class SwingingArm : MonoBehaviour
    9. {
    10.     //GameObjects
    11.     public GameObject LeftHand;
    12.     public GameObject RightHand;
    13.     public GameObject CenterEyeCamera;
    14.     public GameObject ForwardDirection;
    15.  
    16.     //Vector3 positions
    17.     private Vector3 PositionsPreviousFrameLeftHand;
    18.     private Vector3 PositionPreviousFrameRightHand;
    19.     private Vector3 PlayerPositionThisFrame;
    20.     private Vector3 PlayerPositionPreviousFrame;
    21.     private Vector3 PositionThisFrameLeftHand;
    22.     private Vector3 PositionThisFrameRightHand;
    23.  
    24.     //Speed
    25.     public float Speed = 70;
    26.     private float HandSpeed;
    27.  
    28.     // Start is called before the first frame update
    29.     void Start()
    30.     {
    31.         //Set original Previous frame positions at start up
    32.         PlayerPositionPreviousFrame = transform.position;
    33.         PositionPreviousFrameLeftHand = LeftHand.transform.position;
    34.         PositionPreviousFrameRightHand = RightHand.transform.position;
    35.     }
    36.  
    37.     // Update is called once per frame
    38.     void Update()
    39.     {
    40.         //Get the forward direction from the center eye camera and set it to the forward direction object
    41.         float yRotation = CenterEyeCamera.transform.eulerAngles.y;
    42.         ForwardDirection.transform.eulerAngles = new Vector3(0, yRotation, 0);
    43.  
    44.         //Get current positions of hands
    45.         PositionThisFrameLeftHand = LeftHand.transform.position;
    46.         PositionThisFrameRightHand = RightHand.transform.position;
    47.         //position off Player
    48.         PlayerPositionThisFrame = transform.position;
    49.  
    50.         //Get distance the hands and player has moved since last frame
    51.         var playerDistanceMoved = Vector3.Distance(PlayerPositionThisFrame, PlayerPositionPreviousFrame);
    52.         var leftHandDistanceMoved = Vector3.Distance(PositionsPreviousFrameLeftHand, PositionThisFrameLeftHand);
    53.         var rightHandDistanceMoved = Vector3.distance(PositionPreviousFrameRightHand, PositionThisFrameRightHand);
    54.  
    55.         //Add them up to get the handspeed from the user minus the movement of the player to neglect the movement of the player from The equation
    56.         HandSpeed - ((leftHandDistanceMoved - playerDistanceMoved) + (rightHandDistanceMoved - playerDistanceMoved));
    57.  
    58.  
    59.         if (Time.timeSinceLevelLoad > 1f)
    60.             transform.position + = ForwardDirection.transform.forward * Speed * Time.deltaTime;
    61.  
    62.  
    63.  
    64.         //Set previous positions of hands for the next frame
    65.         PositionsPreviousFrameLeftHand = PositionThisFrameLeftHand;
    66.         PositionPreviousFrameRightHand = PositionThisFrameRightHand;
    67.         //Set player position previous frame
    68.         PlayerPositionPreviousFrame - PlayerPositionThisFrame;
    69.  
    70.  
    71.     }
    72. }
    73.  
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    += is a single operator, so it can't have a space between the two. (Basically this means, "add (stuff to the right) to transform.position")
     
    PraetorBlue likes this.