#Automatic Fire
1 messages · Page 1 of 1 (latest)
yup thanks
Need a few minutes to get my head around logic. The code is for Button when Held, so it never triggers the first time
so i have another script with the use thing
did you run the script I linked, or did you modify it to work?
should i send you that
sure
can you speak german just asking
No, I only studied it for one year half a lifetime ago. Göten tag.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
so the use thing is a bit more down
bassicly the script has a lot in it
isch spreissen nicht deutch (?)
i followed a youtube tutorial
ich spreche kein deutsch :=
i dont know french
did you find anything usefull on the link i send ya
cool
public class PlayerController : MonoBehaviourPunCallbacks, IDamageable
MonoBehaviour, PunCallbacks ?
or did you make your own variation of MonoBehavior?
i dont think so
then you might be missing a comma there
where
so i put that in line 9 after a comma
if there was no error, then no need
no error
before or after?
i think the problem is in the shooting script
what do you mean
before
nvm, I thought it was an error
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
this is the shooting script
public override void Use()
{
cooldownTimer -= Time.deltaTime;
if (Input.GetButton("Fire1") && cooldownTimer <= 0)
{
Shoot();
cooldownTimer = rateOfFire;
}
else if (Input.GetButtonDown("Fire1"))
{
Shoot();
cooldownTimer = rateOfFire;
}
}
remove the void Update I added
keep the variables rateOfFire and cooldownTimer
I removed Mathf.Clamp, since I realized it was not necessary
this means cooldownTimer also tells you how long since you last fired your weapon (but in negative numbers + rateOfFire)
hmm, I might have to add this in the other script. Let me know how it goes.
ok lets see if i mange to get that done
i dont manage to get that done
what, specifically?
where i have to put your code in without getting 10000 errors lol
should i replace public override void with your code?
yes
ok
I rewrote that entire segment
but I kinda see now that the input triggers are in the other script
so at this moment, I am sure the first one will fail
it might work, but still bad logic
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
brb
is this right?
k
but also, I think my IF statement logic is bad
I'm rewriting for the other script, brb
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
now?
missing the end curly-bracket } for Use()
36
sec, I think I have fixed it
in PlayerController
delete the following
if(Input.GetButtonDown("Fire1"))
{
items[itemIndex].Use();
}
ok lemme try that
then replace it with
if (cooldownTimer <= 0)
{
// Click
if(Input.GetButtonDown("Fire1"))
{
items[itemIndex].Use();
cooldownTimer = rateOfFire;
}
// Hold
else if(Input.GetButton("Fire1"))
{
items[itemIndex].Use();
cooldownTimer = rateOfFire;
}
}
and add these variables on the top
float rateOfFire = 0.5f;
float cooldownTimer;
(undo all the other changes - I did this from scratch, without the stuff you tried earlier)
and change rateOfFire = 0.1f; or something
so in player controller i have to paste in that
right?
yes
and in the other script i have to delete everything right?
like go back
where i was at the start
let me test that
nothing
can i send ya what i did
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
maybe did i do that thing on the top wrong
nope
ok
i can shoot one time
and then not
public override void Use()
{
Shoot();
}
is this still in the other script?
1 shot
hm
what do i have to do with that
post your current SingleShotGun script
i will post both i think i made something wrong in the player controller stuff
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
shooting script
player script
if (cooldownTimer <= 0)
if (cooldownTimer <= 0f)
change the zero to a float, try again
what ? i dont understand what you mean
but both of them have an f
often it doesn't matter, but since we are testing for a bug, it's best to make sure all numbers are cast to the same type
if (cooldownTimer <= 0)
line 103
nope 1 shoot
once
and then never
Debug.Log("Click");
Debug.Log("Hold");
put these in their respective if-statements
i do not understand
if (cooldownTimer <= 0)
{
// Click
if (Input.GetButtonDown("Fire1"))
{
items[itemIndex].Use();
cooldownTimer = rateOfFire;
}
// Hold
else if (Input.GetButton("Fire1"))
{
items[itemIndex].Use();
cooldownTimer = rateOfFire;
}
}
to test whether any of the statements are triggered, add a debug log to each of them
so i add the debug log to both of them
with different texts, so you know which one is triggered
as long as it is within the same curly-bracket code segment
what do you mean
i will send you the code again
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Okay. Take a minute and breathe.
Look at the Debug.Log() lines you entered
then read line 105 and 113
i dont get it
and you are indeed holding down the button?
ok. ANd you can only fire once?
Were you able to fire multiple times before I started helping?
revert your code back to that time
test that it works, then post the code to me
yes
k
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i can spam again
A tool for sharing your source code with the world!
copy it
go to your script
mark all
paste
YES
i can hold now
but can i change the firerate in any way?
it seems to fast for me
very cool
so i have another weapon like a pistol if i change the script here it will also change it for the pistol right?
if you didn't copy/paste the entire script earlier, that might be why it didn't work
I used better logic this time, but it should essentially be 100% the same.
Remember to never make assumptions, and reduce as many assumptions as possible
When trying to fix problems, a good point is to search every corner, even the ones you think you know
Very nice that we made it :)
it works great VERY MUCH thanks but yeah how can i change it so it has different values on another weapon
is there way to make that happen
but yeah thank you so much
it took me 4 dayys
jesus
thanks
that depends on how you've structured your project
ideally, the rate of fire is a property of the weapon itself
or it contains a value which it gives to rateOfFire, whenever it is equipped
I am guessing you want to add rateOfFire to the Gun class
you're very welcome
yes something like that
like i dont want my pistol to shoot at the same speed as the assault rifle
yeah that would be broken. there is a reason those are banned in real life xD
XD
not everywhere ofc
so is there a way for that
maybe to make the firerate a public class
oh no
wait
nah that would not fix anthing
the quickest fix I see
tell me
is adding a float to Gun
named rateOfFire
and whenever a weapon is equipped
rateofFire = yourGun.rateOfFire;
how can i do that
link your Gun class
what do you mean
show it to me
k
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Gun : Item
{
public abstract override void Use();
public GameObject bulletImpactPrefab;
}
so at this moment, none of the guns have different attributes?
no?
are you following a guide or writing this from scratch yourself?
guide
have you completed the entire guide?
yes
the pistol has a different damge thing
like i can change the damage on the pistol
where is the different damage for guns coded?
i have to look
guninfo
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "FPS/New Gun")]
public class GunInfo : ItemInfo
{
public float damage;
}
this is the script
try adding a public float rateOfFire;
ok
should i just copy public float rateOfFire
i did that
can i try it
ok i can change rate of fire
there is already a public float damage there
i will test f it does anything
you literally just add another float witrha different name
but at this point, it kind of stops for me.
It's nearly midnight, and I am barely familiar with the design pattern of your project.
From this point, you should ask in the channel again. People there have more diverse experience.
Your goal has to be understand the code. And I suspect you will learn a great deal once you figure out how to connect this last dot.
The last thing you need to fix, is to see how the float damage is called when you equip your weapon.
You need to do the same for the float rateOfFire
can i ask how i do that or are you done now
i think i found it in the singleshotgun code
hit.collider.gameObject.GetComponent<IDamageable>()?.TakeDamage(((GunInfo)itemInfo).damage);
that's what I don't have the time to figure out for you
and I also believe you should fix that part yourself. it should be simple, as you just need to follow the logic of the damage float
hmm i think i can manage to do this but still thanks for all your help
if i have question i will ask them in beginner code again
what line is this code at?
28
hm. it's functional, but there might be a performance issue down the line.
It's standard practice to get components only once, and beforehand, because it is slow.
But in this case I don't think it matters at all.
hmm ok
is there an Equip Weapon method?
like in a script?
no equip
inside that method, get the rateOfFire of the weapon
and then set the global rateOfFire to that value
item info
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemInfo : ScriptableObject
{
public string itemName;
}
item
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Item : MonoBehaviour
{
public ItemInfo itemInfo;
public GameObject itemGameObject;
public abstract void Use();
}
hm, yeah, go to the channel again lol
try General Code or Advanced
Have a nice evening man. Good luck with your game o/
thanks good night 🙂
Simplest approach is to change the cool down according to your current equipped weapon in that firerate script. For that you need to save firerate(the cool down float value) somewhere and it has to be accessible by code.
You can add a script to your weapon which has that data, or use a scriptable object for it
LOL how do that
You already have that
float damage
float rateOfFire
are in a scriptable object
search "scriptable object" in that article
it shows good examples of how to refer to the variables
And how can I use that on my script
public class PlayerHealth : MonoBehaviour
{
AudioSource playerAudioSource;
void Start()
{
playerAudioSource = GetComponent<AudioSource>();
}
}
Can I use something like that on my script or should I wait until you have time for me again
the article is very long. you need to search inside the website for "scriptable object"
Ideally, I recommend you read the entire article. It is extremely good at explaining how to reference all sorts of variables.
I will be rather busy this week, so I'm not sure I if I will have the time.
If I come up with a solution, I will let you know.
Fixing your problem would require me to learn how your programming pattern works.
And at that point, it makes more sense that you do the research yourself.
But since you seem to be in way over your head, you should try to get help from someone who knows how this pattern works.
in simplicity, you need to set the script's private float rateOfFire to the gun's rate of fire, somewhere in the Equip process
I don’t think I have a equip process
But yeah I will do my own research
so if i find the code with the equip thing i will manage to do this myself right?
lol
There is an Equip() function in your script
inside that one, you have to somehow refer to the rateOfFire variable (of the gun)
it should be similar to how the damage is retrieved
but I didn't recognize the code which did exactly that
should i send you the codes again?
and what do you mean with somehow
damage is retrieved in a complete different way
we can forget how damage is retrieved
hit.collider.gameObject.GetComponent<IDamageable>()?.TakeDamage(((GunInfo)itemInfo).damage);
this is the damage part
and i dont think we can put something like this on the code
where do i have to put it in
without the other stuff
try writing a line of code that leads to the Rate Of Fire float
do you have a example code for me ?
No, I have no idea how to do it with your design pattern.
Did you read the article I linked?
the object holding the floats for damage and rateoffire for your guns, is a scriptable object
maybe re-check that paragraph
or ask in one of the other channels
lemme check that
i see nothing
seems like i cant find a fix for that problem
the only thing you need to know, is how to reference a scriptable object's variable, within the design pattern which makes up your code
is it possible to make an if statement so it is like
when 1 is equiped
change the firerate variable to this
and when 0 is equipped do this
yes - but if you're getting data from the weapon, then you should just as easily get the other variables
or is that from the array that chooses weapons?
yup
but will it work as a fast fix or not?
Well, you could set it there. It would work.
But it's much more code.
but would it be more easy ? bc i cant seem to get it done without your help but next week i will have an online c sharp class they will teach me the basics
Look. I visit beginner-code to help people start coding, and teach them how to do the basic stuff.
What you have here is not a beginner type of code.
For some reason, you are lacking very basic knowledge, yet you have chosen to use this design pattern.
What you are trying to achieve is beyond me - because you might end up with a "finished product" but you risk learning nothing.
I do not have the knowledge or time to help you.
I have looked over your efforts in the other channels.
You need to look more at the examples around you who actually received help.
Don't ask for help - post the issue - describe it in every way that you can, and explain what you are trying to achieve.
If you define your question properly, you will attract the more competent people who want to help.
ok thanks for the tipp
You're welcome.
One thing that might make it easier to get help, is upload a compressed rar/zip of your project
I think it is necessary due to the structure of your code
i will finish my map and stuff for the my game will only have one weapon as it seems but yeah thanks for all the help you gave me
I do hope you fix it before your deadline. Best of luck, man o7