|
|
|
| View previous topic :: View next topic |
NectoMortis
Joined: 18 Dec 2008 Posts: 5 Location: London
|
Posted: Tue Nov 03, 2009 7:22 pm Post subject: Javascript Help |
|
|
|
I've been doing this tutorial:
http://www.unitytutorials.com/video/290/muzzle-flash--raycasting--bullet-explosion1
and when I finished it worked fine. Now all of a sudden it wont work, can anyone tell me what's wrong with these scripts:
| Code: | var muzzleFlash :GameObject;
var values:Array;
var angle :int;
var bullet :Rigidbody;
var speed :int;
function Start ()
{
values = new Array();
values.length = 6;
values[0] = 220;
values[1] = 400;
values[2] = 100;
values[3] = 340;
values[4] = 72;
values[5] = 612;
for(var value :int in values)
{
angle = value;
}
}
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
transform.Rotate(0,0,angle);
var instantiatedFlash = Instantiate(muzzleFlash, this.transform.position, this.transform.rotation);
var instantiatedBullet = Instantiate(bullet, this.transform.position, this.transform.rotation);
instantiatedBullet.velocity = transform.TransformDirection(Vector3.forward * speed);
instantiatedFlash.transform.Rotate(-90,0,0);
Destroy(instantiatedFlash, .03);
}
} |
and this one:
| Code: | var explosion:Transform;
var point :Vector3;
var explosionRotation :Quaternion;
function Update()
{
var hit :RaycastHit;
var fwd : transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(this.transform.position,fwd,hit,1))
{
point = hit.point;
explosionRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
Explode();
}
}
function Explode()
{
Destroy(this.gameObject);
var instanExplosion = Instantiate(explosion, point, explosionRotation);
} |
This error message always comes up when I try to play the second script, in the editor:
| Quote: | | Assets/Explosion.js(8,47): UCE0001: ';' expected. Insert a semicolon at the end. |
I just can't seem to fix it; and now that the whole thing has stopped working, I have no idea.
When I try to fire nothing happens, nothing instantiates. I suspect it may be something to do with it not recognising the button press.
Thanks |
|
| Back to top |
|
|
Timmer

Joined: 28 Jul 2008 Posts: 334 Location: San Diego, CA
|
Posted: Tue Nov 03, 2009 8:10 pm Post subject: |
|
|
|
Hello,
I *think* your error is on that line but the wording is throwing you off:
| Code: | | var fwd : transform.TransformDirection(Vector3.forward); |
The : in JS says "this is of type" but you're actually creating an object there. I think what you want is:
| Code: | | var fwd = transform.TransformDirection(Vector3.forward); |
|
|
| Back to top |
|
|
NectoMortis
Joined: 18 Dec 2008 Posts: 5 Location: London
|
Posted: Tue Nov 03, 2009 8:46 pm Post subject: |
|
|
|
Thanks a bunch  |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|
|
|
|