- Home /
Odd scripting error
Why is this code not working? It should work just fine as written but it keeps giving an insert semicolon error.
var attractedTo : GameObject ;
var strengthOfAttraction : float = 5.0f;
function Update()
{
Vector3 direction = attractedTo.transform.position - transform.position;
rigidBody.AddForce(strengthOfAttraction * direction);
}
Answer by robertbu · Jul 20, 2014 at 05:05 AM
You are using a C# style declaration on line 6. Line 6 should be:
var direction = attractedTo.transform.position - transform.position;
...or:
var direction : Vector3 = attractedTo.transform.position - transform.position;
For future questions, please include a copy of the error message from the console. The message gives us the line number of the error and the stack trace.
Thanks so much. Obviously I'm still learning scripting but I was scratching my head all night on this. Thanks.
Answer by fifthknotch · Jul 20, 2014 at 05:06 AM
Vector3 direction = attractedTo.transform.position - transform.position;
is written in c# whereas the rest of your code is written in UnityScript. rewrite that to:` var direction : Vector3 = attractedTo.transform.position - transform.position;`
Your answer
![](https://koobas.hobune.stream/wayback/20220613154524im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Something Wrong With My Script 0 Answers
Script attached to 'Main Camera' in scene '' is missing or no valid script is attached. 0 Answers
How to make a smooth transition between Vector3's 2 Answers
Script is not working at all 2 Answers