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

Coding Error

Discussion in 'Scripting' started by MalcolmPlays, Feb 14, 2015.

  1. MalcolmPlays

    MalcolmPlays

    Joined:
    Feb 11, 2015
    Posts:
    15
    I am really new to Unity and I was just coding something and this created an error.

    Assets/AI Testing/AISimple.js(36,45): UCE0001: ';' expected. Insert a semicolon at the end.

    It says to insert a semicolon at the end of line 36 I do that and it just creates more errors. Please Help!
     
  2. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    The error might be in an earlier line of code, it could be a mismatched bracket { or a missing semi-colon on an earlier line.... would be easier to help if you posted code. Remember to use code tags when posting code, or use the insert button on the forum entry box
     
    Kiwasi likes this.
  3. MalcolmPlays

    MalcolmPlays

    Joined:
    Feb 11, 2015
    Posts:
    15
    Ok thanks heres the code

    var Distance;
    var Target : Transform;
    var lootAtDistance = 25.0;
    var attackRange = 15.0;
    var moveSpeed = 5.0;

    function Update ()
    {
    Distance = Vector3.Distance(Target.position, transform.position);

    if (Distance < lookAtDistance)
    {
    renderer.material.color = Color.yellow;
    lookAt();
    }

    if (Distance > lookAtDistance)
    {
    renderer.material.color = Color.green;
    }

    if (Distance <attackRange)
    (
    renderer.material.color) = Color.red;
    attack();
    }

    function lookAt ()
    {
    var rotation = Quaternion.LookRotation; Target.position = transform.position;
    transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime);
    }

    function attack ()
    {
    transform.Translate(Vector3.forward) moveSpeed = Time.deltaTime;
    }
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Messed up braces an brackets here.
     
  5. MalcolmPlays

    MalcolmPlays

    Joined:
    Feb 11, 2015
    Posts:
    15
    I changed it and this is what I got in errors thanks for the reply!

    Assets/AI Testing/AISimple.js(28,10): BCE0044: expecting (, found 'lookAt'.
    Assets/AI Testing/AISimple.js(28,19): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/AI Testing/AISimple.js(34,10): BCE0044: expecting (, found 'attack'.
    Assets/AI Testing/AISimple.js(34,19): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/AI Testing/AISimple.js(36,45): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/AI Testing/AISimple.js(39,1): BCE0044: expecting }, found ''.
     
  6. lordconstant

    lordconstant

    Joined:
    Jul 4, 2013
    Posts:
    389
    Code (CSharp):
    1.  
    2. function Update ()
    3. {
    4.     Distance = Vector3.Distance(Target.position, transform.position);
    5.  
    6.     if (Distance < lookAtDistance)
    7.     {
    8.         renderer.material.color = Color.yellow;
    9.         lookAt();
    10.     }
    11.  
    12.     if (Distance > lookAtDistance)
    13.     {
    14.         renderer.material.color = Color.green;
    15.     }
    16.  
    17.     if (Distance < attackRange)
    18.     {
    19.         renderer.material.color = Color.red;
    20.         attack();
    21.     }
    22. }
    23.  
    Your fixed update should look like that i think.
    You may have missed a brace when you fixed it leading to the other errors.
     
  7. MalcolmPlays

    MalcolmPlays

    Joined:
    Feb 11, 2015
    Posts:
    15
    Ok I copy and pasted that script and put it in it all went down to one error

    Assets/AI Testing/AISimple.js(36,45): UCE0001: ';' expected. Insert a semicolon at the end.
     
  8. lordconstant

    lordconstant

    Joined:
    Jul 4, 2013
    Posts:
    389
    i think i spotted the problem in the attack function.

    transform.Translate(Vector3.forward) moveSpeed = Time.deltaTime;

    You are doing two things here and i believe you want to only move the object forward by your speed based on the frame time.

    transform.Translate(Vector3.forward);
    moveSpeed = Time.deltaTime;

    That is what you wrote minus the semi colon which was causing your error.
    This would move the object forward by the vector not based on your speed then set the move speed to the current frame time.

    I've attached the fixed code below, which will move your object based on your speed. :)

    Code (CSharp):
    1.  
    2. function attack ()
    3. {
    4.     transform.Translate(Vector3.forward * (moveSpeed * Time.deltaTime));
    5. }
    6.  
     
  9. MalcolmPlays

    MalcolmPlays

    Joined:
    Feb 11, 2015
    Posts:
    15
    Hey I sent a conversation to your account could you check that out :)
     
  10. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Dunno if you've fixed this already but
    Code (csharp):
    1. var rotation = Quaternion.LookRotation; Target.position = transform.position;
    should be
    Code (csharp):
    1.  
    2. var relativePos = Target.position - transform.position;
    3. var rotation = Quaternion.LookRotation(relativePos);
    from here http://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html