- Home /
BCE0044: expecting }, found 'private'. PLEASE HELP!!!!!
Here is my code. WHAT IS WRONG?! PLEASE ANSWER AS SOON AS POSSIBLE!!!
var LookAtTarget : Transform;
var damp = 1.0;
var BulletPrefab : Transform;
var savedTime;
function Update()
{
if(LookAtTarget)
{
var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
var bps = 1.00;
private var savedtime:float=0;
if(Time.time>bps+savedtime)
{
savedtime=Time.time;
Shoot();
}
}
function Shoot()
{
var bullet = Instantiate(BulletPrefab, gameObject.Find("spawnPoint1").transform.position, Quaternion.identity);
bulet.Rigidbody.AddForce(transform.forward * 1000);
}
Answer by aldonaletto · Feb 13, 2013 at 01:06 AM
You should format your code: select the code and press the 101/010 button or Ctrl-K.
I formatted the code for you, and found the unexpected private keyword in line 15: remove it - private should be used only in member variables (variables declared outside any function).
Thank you. That worked. The problem now is my turret is shooting like crazy... is there a way for it to NOT shoot like crazy? in a easy code preferably. thanks!
You are redeclaring "savedTime" in your update function, this new declaration will "shadow" the class member and always be initialized to zero, causing your turret to shoot every frame.
Answer by Dave-Carlile · Feb 13, 2013 at 01:03 AM
Line 15. You can't declare a local variable as private. Just remove private
.
Thank you. That worked. The problem now is my turret is shooting like crazy... is there a way for it to NOT shoot like crazy? In a easy code preferably, thanks!