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

Question Quick Question

Discussion in 'Scripting' started by DelgadoUprep, Aug 15, 2022.

  1. DelgadoUprep

    DelgadoUprep

    Joined:
    Jun 28, 2022
    Posts:
    9
    I'm working on making an arrow pull for VR and keep getting the code below. Not sure where I'm missing the ";". Any help is appreciated!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class arrowpull : MonoBehaviour
    6. {
    7.  
    8. private float CalculatePull(Vector3 pullPosition)
    9. {
    10. Vector3 pullDirection = pullPosition - start.position;
    11. Vector 3 targetDirection = end.position - start.position;
    12. float maxLength = targetDirection.magnitude;
    13.  
    14. targetDirection.Normalize();
    15. float pullValue = Vector3.Dot(pullDirection, targetDirection) / maxLength;
    16. return Mathf.Clamp(pullValue, 0, 1);
    17. }
    18.  
    19.     // Start is called before the first frame update
    20.     void Start()
    21.     {
    22.        
    23.     }
    24.  
    25.     // Update is called once per frame
    26.     void Update()
    27.     {
    28.        
    29.     }
    30. }
    31.  
     
  2. DelgadoUprep

    DelgadoUprep

    Joined:
    Jun 28, 2022
    Posts:
    9
    forgot to add the error codes:
    Assets\arrowpull.cs(11,8): error CS1002: ; expected

    Assets\arrowpull.cs(11,10): error CS1002: ; expected
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,523
    Wrong forum, this is a scripting question. I'll move your post there.

    The error tells you the line and column and what the problem is i.e. missing a ";" so does this explain the error to you?
     
  4. DelgadoUprep

    DelgadoUprep

    Joined:
    Jun 28, 2022
    Posts:
    9
    Thanks, I believe I already have the ; at the end of those lines but I may be wrong. Thanks for moving this question to the right place, where can I find it to track answers?
     
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,527
    The errors can sometimes be misleading, especially when you completely messed up the syntax. Completely sounds strong, but you have to see the code from the compilers perspective. Compilers do have zero tolerance and no room for interpretation. We as humans look at your line 11 and immediately know that you meant to write
    Vector3
    instead of
    Vector 3
    .

    However a compiler sees
    Vector
    which is an unknown identifier which is followed by the number
    3
    followed by another unknown identifier
    targetDirection
    So this does not resemble any valid syntax rules in C#. Though the compiler simply got confused and recommends to place a semicolon at character 8 as this is his best guess that this could solve the issue. Of course this would not solve anything. The compiler is pretty dumb. It does not know what you may had in mind.
     
  6. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    Code (CSharp):
    1. Vector 3 targetDirection = end.position - start.position;
    You can't just put a space there, it's Vector3 not Vector 3.
     
  7. DelgadoUprep

    DelgadoUprep

    Joined:
    Jun 28, 2022
    Posts:
    9
    thnkx
    Thanks!