Your code is quite confusing and not as readable. This problem stems from its format/layout. You should definitely indent your curly brackets to better understand what piece of code lies in each scope of the project.
Line 10: Needs to be Update (capital "U")
function update ()
Line 16 Needs to be rigidbody.isKinematic
rigidbody.iaKinematic = false;
Line 25: Needs to be GetComponent(Collider).enabled = false;
GetComponent(Collider) = false;
Line 27: Needs to be rigidbody.isKinematic
rigidbody.iaKinematic = true;
Line 30: Needs to be transform.rotation
trasform.rotation = posizioneT.rotation;
These were the ones I could find; hopefully there isn't more. This next part is difficult because I can't tell if some of the *if* statements are within the same scope or on their own (if they're inside of another *if* statement or by itself.
The *if* statement @ Line 37 has 2 *else* statements which is not possible. It can be:
// first option
if ( option1 )
{
// do something
}
// second option
else if ( option2 )
{
// do something
}
// neither option
else
{
// do something
}
or:
// first option
if ( option1 )
{
// do something
}
// second option
else ( option2 )
{
// do something
}
**NOTE**: You should really indent for class, function, enum, if, for, etc.
The *if* statement on line 19 encapsulates the rest of the script. Is this suppose to happen or should there be a closing bracket on line 31?
// line 19 below
if(Input.GetButtonDown("Fire1") && Vector3.Distance(transform.position, mainCamera.position) < maxDist && Vector3.Angle(transform.position - mainCamera.position, mainCamera.forward) < maxAngolo);
{
raccolta = true;
}
else
{
GetComponent(Collider) = false;
rigidbody.useGravity = false;
rigidbody.iaKinematic = true;
transform.parent = mainCamera;
transform.position = posizioneT.position;
trasform.rotation = posizioneT.rotation;
// line 31
I attempted to format your code, but as I previously stated, I don't know where your closing brackets should be, so it may be incorrect. After looking at the new format, you can easily fix the misplaced brackets.
After looking more at the code, the *if* statements look out-of-order. You have 2 *if* statements with the same condition setting the same variable to different values. I'm not sure what it suppose to happen, but here is the formatting at least...
var raccolta : boolean;
var posizioneT : Transform;
var maxDist : float;
var maxAngolo : float;
var mainCamera : Transform;
var accesa : boolean;
var luce : Light;
var moltiplucatore : float;
function Update ()
{
if (!raccolta)
{
GetComponent(Collider).enabled = true;
rigidbody.useGravity = true;
rigidbody.isKinematic = false;
transform.parent = null;
if (Input.GetButtonDown("Fire1") && Vector3.Distance(transform.position, mainCamera.position) < maxDist && Vector3.Angle(transform.position - mainCamera.position, mainCamera.forward) < maxAngolo);
{
raccolta = true;
}
else
{
GetComponent(Collider) = false;
rigidbody.useGravity = false;
rigidbody.isKinematic = true;
transform.parent = mainCamera;
transform.position = posizioneT.position;
transform.rotation = posizioneT.rotation;
}
if (accesa)
{
luce.intensity -= Time.deltaTIme * 0.1 * moltiplicatore;
luce.enabled = true;
}
if (Input.GetButtonDown("Fire2")) accesa = false;
if (Input.GetButton("Fire3"))
{
luce.range = 15;
luce.spotAngle = 12;
}
else
{
luce.range = 10;
luce.spotAngle = 30;
}
luce.enabled = false;
if (Input.GetButtonDown("Fire2")) accesa = true;
}
}
Hope this helps!
↧