Script Writing with Unity3D

Computer guy1441

Honorable
Aug 9, 2013
8
0
10,510
I am making a game in unity 3D and i'm writing script for the melee portion of the game but i keep getting the following error BCE0043: unexpected token : (.
this is my script
#pragma strict

var TheDamage : int = 25;
var Distance : float;

function update ()

(Input.GetButtonDown("Fire1");
{
var hit : RaycastHit;

if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
 

Black_Plague

Reputable
Jun 29, 2014
97
0
4,660
Soorrrry for late response. I m not a programmer, but i am learning xD. I am not sure, but i think uppercase variables caused that. Because unity's javascript categorize variables and functions by name. Try "theDamage" and "Distance"
Also dont forget to change Distance=hit.distance etc.
You can improve your code by adding 1 shot sound. You know var sound1 : audioclip; var sound2 : audioclip; goes on as you wish.
Then add a var randomizer : float;
Then put this after "if (Input.GetButtonDown("Fire1"))"
Aha found it you forgot second ")" and put a semicolon :3.
Anyway add this after input check
randomizer = random.range(0,//how many sound examples you have)
If (randomizer=>0 && randomizer=<1)
audio.play(sound1);
If (randomizer=>1 && randomizer=<2)
audio.play(sound2);
Goes on...
You can also add a delay between shots.
Add these variables
var canShoot : boolean = true;
var delay : float 3.0;
var timer : float = 0.0;
Add these too...
Function Delay()
If (!canShoot)
{
timer+=time.deltaTime;
If (timer=>delay)
{
timer=0.0;
canShoot=true;
}
}
And dont forget to add this line to function Update()
function Delay()
Goodluck with your project. Sorry for bad english, late response and typos. Typing from phone.