#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. }
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