Search Unity

Question Why does it say "Assets\Scripts\PlayerFollow.cs(26,10): error CS1002: ; expected"?

Discussion in 'Scripting' started by captainbunnerton, Nov 19, 2022.

  1. captainbunnerton

    captainbunnerton

    Joined:
    Oct 22, 2020
    Posts:
    2
    Here is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class PlayerFollow : MonoBehaviour
    5. {
    6.     public GameObject player;
    7.     private Vector3 offset;
    8.     private bool switch;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.      
    13.     }
    14.     // Update is called once per frame
    15.     void LateUpdate()
    16.     {
    17.         switch = Input.GetButton("Fire1");
    18.         if (switch == true)
    19.         {
    20.             offset = new Vector3(0, 2, 1);
    21.         }
    22.         else
    23.         {
    24.             offset = new Vector3(0, 8, -7.5f);
    25.         }
    26.         transform.position = player.transform.position + offset;
    27.     }
    28. }
     
  2. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,338
    The problem might be here
    private bool switch;
    . "switch" is a reserved keyword with a special meaning. Change that to another name and you should be fine.
     
    mopthrow likes this.
  3. captainbunnerton

    captainbunnerton

    Joined:
    Oct 22, 2020
    Posts:
    2
    It worked! Thanks for the help!