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

Bug Problems with ; expected

Discussion in 'Scripting' started by Sindaga, Jun 23, 2023.

  1. Sindaga

    Sindaga

    Joined:
    Feb 14, 2023
    Posts:
    15
    so I was in lesson 5.1 and I found a ; expected but I cant find it


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Target : MonoBehaviour
    {
    private Rigidbody targetRb;
    private float minSpeed = 12;
    private float maxSpeed = 16;
    private float maxTorque = 10;
    private float xRange = 4;
    private float ySpawnPos = -6;

    // Start is called before the first frame update
    void Start()
    {
    targetRb = GetComponent<Rigidbody>();
    targetRb.AddForce(RandomForce(), ForceMode.Impulse);
    targetRb.AddTorque(RandomTorque(), RandomTorque(), RandomTorque(), ForceMode.Impulse);

    rtansform.position = Vector3 RandomSpawnPos();
    }

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

    }

    Vector3 RandomForce()
    {
    return Vector3.up * Random.Range(minSpeed, maxSpeed);
    }

    float RandomTorque()
    {
    return Random.Range(-maxTorque, maxTorque);
    }

    Vector3 RandomSpawnPos()
    {
    return new Vector3(Random.Range(-xRange, xRange), ySpawnPos);
    }
    }
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,977
    I mean what line is the error supposed to be?
     
  3. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,834
    Use code tags to make things more readable.

    The error message will tell you what line and column number like this:
    error: what is wrong (12,34)
    - the numbers are the compiler's best guess for line and column number.

    You misspelled
    transform
    in Start, but that would not be a semicolon-expected error. The rest of that line makes no sense. You say Vector3 for no apparent reason there.
     
    Bunny83 likes this.
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    It's going to be the issue. If the compiler can't make heads or tails of the syntax it'll typically default to some very basic "expected" this or that message.
     
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,834
    The unknown symbol won't be a semicolon error.

    The rest of the stuff after the assignment will likely be a semicolon error.
     
    Bunny83 likes this.
  6. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    510
    There's two issues.

    rtansform.position = Vector3 RandomSpawnPos();

    Should be:

    transform.position = RandomSpawnPos();
     
  7. Sindaga

    Sindaga

    Joined:
    Feb 14, 2023
    Posts:
    15
    Thank you zulo now it works correctly