I need help with my raycast shooting script

#pragma strict

var Effect : Transform;
var TheDamage = 100;
function Update () {

    var hit : RaycastHit;
    var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
   
    if (Input.GetMouseButtonDown(0))
    (
        if (Physics.Raycast (ray, hit, 100))
        (
            var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
            hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReciever);
        )
    )
   
}

I get these errors:
Assets/Standard Assets/Characters/FirstPersonCharacter/Prefabs/raycastshooting.js(13,17): BCE0043: Unexpected token: if.
Assets/Standard Assets/Characters/FirstPersonCharacter/Prefabs/raycastshooting.js(13,20): BCE0044: expecting ), found ‘(’.
Assets/Standard Assets/Characters/FirstPersonCharacter/Prefabs/raycastshooting.js(13,21): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/Standard Assets/Characters/FirstPersonCharacter/Prefabs/raycastshooting.js(13,52): BCE0043: Unexpected token: ).
Assets/Standard Assets/Characters/FirstPersonCharacter/Prefabs/raycastshooting.js(15,25): BCE0043: Unexpected token: var.
Assets/Standard Assets/Characters/FirstPersonCharacter/Prefabs/raycastshooting.js(15,29): BCE0044: expecting ), found ‘particleClone’.
Assets/Standard Assets/Characters/FirstPersonCharacter/Prefabs/raycastshooting.js(16,116): BCE0043: Unexpected token: ;.

Your syntax is wrong. You are using parenthesis, when you should be using curly braces, to enclose the lines within your if-statement.
It should be like this.

10.    if (Input.GetMouseButtonDown(0))
11.    {
12.        if (Physics.Raycast (ray, hit, 100))
13.        {
14.            var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
15.            hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReciever);
16.        }
17.    }

{ } => scope block
( ) => mathematical parenthesis or function parameters

also it would appear your shift key is stuck :stuck_out_tongue:

Thanks so much, i have one more question though, how do i get the effect to disappear in a set amount of time?

You can use the “Clock” class and if the “duration” is higher than a threshold, delete your object or do what ever you like to do.

There’s no Clock class in Unity.

Destroy has an optional parameter for delay. Just use that.

// remove effect after 3 seconds
Destroy(particleClone.gameObject, 3);
1 Like

Although KelsoMRK’s suggestion will get the job done, It would be best if you just created a pool of objects, and then recycle the objects when you are done with them opposed to instantiating and destroying every time you need a bullet.
It might be a pain to set up the pooling system, but in the long run it would be very beneficial.

Given that OP was having trouble with using curly brackets versus parenthesis I assumed pooling systems were probably a bit above their current skillset. Baby steps :slight_smile:

I understand where you were coming from, but I just wanted to point Legosdoctor in the right direction for the future.

LOL, I was watching a video and the brackets looked like parenthesis since the text size was so small

It’s an honest mistake when you’re just beginning. I honestly can’t stand video tutorials about programming.

Good luck :slight_smile: