- Home /
More refined gunshot system
Hi, iam developing an horror FPS game, in this moment iam scripting the gunshot system, buti think my code is too complicated, iam starting with this languages (JS, CS)
these are my codes:
1)--- Damage system with Raycast
var Effect : Transform;
var TheDammage = 30;
function Start() {
}
function Update () {
GunShot();
}
function GunShot (){
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.GetButtonDown("Fire1"))
{ yield WaitForSeconds(0.25);
if (Physics.Raycast (ray, hit, 105))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 0.5);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
2)--- The bullet spawner(just visual effect)
var Bullet : GameObject;
var BulletSpawn : Transform;
function Start () {
}
function Update () {
bulletshown();
}
function bulletshown (){
if(Input.GetButtonDown("Fire1")){
yield WaitForSeconds(0.02);
Instantiate(Bullet ,BulletSpawn.transform.position , BulletSpawn.transform.rotation);
yield WaitForSeconds(1.0);
}
}
3)--- The bullet itself (visual effect only)
var BulletSpeed = 0.4;
function Start () {
}
function Update () {
transform.Translate(Vector3.left * BulletSpeed);
}
(if you are wondering why i put the vector3 on the LEFT, that is because the bullet model which im using is rotated 90 degrees, so i rotated the Bullet spawner 90 degrees to the right, and that is why i put the vector3 on the left instead of FORWARD)
So my question is: can anyone help me to simplify the code? i mean, make a only one JS for this GUN thing? so when i try to put the animation will be more easier to fit with the whole gunshot script instead of modifyng 3 different codes at the same time... whatever, thats what i think... ANOTHER THING!! the "YIELD WAITFORSECONDS" code doesn't work properly, my objetive is delaying the gunshots(because the main weapon is a revolver, and you know... revolver like magnum, a heavy rough shot) and actually the revolver fires more like a damn UZI... ahaha just kidding, but these delays that i put just are delaying the mouse clicks so more than a delayed shot looks like a LAG shot if you know what i mean..
so that it is my problem... and sorry for my lame english :P hopefuly anyone help me, and this for the ones who have similar troubles too(and read this forums) :P
greetings :)
New users with lower karma have to get their questions approved by a moderator before they show up. Please do not post the same question over and over again - be patient and your question will be looked over and approved.
Your answer
Follow this Question
Related Questions
Inspector Assigned Variables Not In Both Scenes 1 Answer
Using Time with OnGUI Help 2 Answers
rigidbody2D only jump while grounded 1 Answer
How do you make a trig object? 0 Answers
How can I make a gui with buttons pop up in javasript? 1 Answer