Expecting EOF, found public
So I wrote this script based off of a script that was used in an answer on this website, but I have a problem: Unity says that public is unexpected and it was expecting the EOF. I'm not sure how to fix this since I'm rather new. This is a script for a shooting gun, and I need the projectile to be public, however the word "public" 1;1 is not recognized in the system. Please help, thank you!
public( Rigidbody )projectile;
public float speed = 20;
// Use this for initialization void Start () {
}
// Update is called once per frame void Update () {
if (Input.GetButtonDown("Fire1"))
{
Rigidbody instantiatedProjectile = Instantiate(projectile,
transform.position,
transform.rotation)
as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
}
}
Answer by pekalicious · Nov 29, 2015 at 11:42 PM
Why did you put RigidBody in parentheses? I'm just curious to know where you got that idea. Anyway, simply remove them and you should be fine:
public Rigidbody projectile;
public float speed = 20;
Without the parentheses, I have these two errors: Unexpected token: rigidbody Unexpected token: float ';' expected. Add a semicolon.
I added to parentheses to take those away, however I'm not sure why it doesn't recognize the 'public'.
Sounds like you either created a javascript file but copied c# code, or you created a c# script but forgot to create the class definition. What type of script are you going for?
I'm going for javascript. I tried copying the script into a C# file, but there are many errors when I do that. When I add a class, it doesn't recognize "Projectile" and "Float." It also wants an extra semicolon.
Javascript and c# have wildly different syntax. Not to mention that you cannot easily have a javascript class talk to a c# class and vise versa.
Here is a short video explaining the differences: https://unity3d.com/learn/tutorials/modules/beginner/scripting/c-sharp-vs-javascript-syntax
I suggest choosing one type of script and sticking with it. $$anonymous$$y recommendation would be c#, but choose whatever you find easier.