Тёмный

Weapon Switching - Unity Tutorial 

Brackeys
Подписаться 1,8 млн
Просмотров 426 тыс.
50% 1

Let's create a system for switching between weapons!
● Sci-Fi Weapons: devassets.com/assets/sci-fi-we...
● Modern Weapons: devassets.com/assets/modern-we...
● Medieval Arena: devassets.com/assets/medieval-...
❤️ Donate: www.paypal.com/donate/?hosted...
····················································································
► Join Discord: / discord
♥ Subscribe: bit.ly/1kMekJV
● Website: brackeys.com/
● Facebook: / brackeys
● Twitter: / brackeystweet
········································­­·······································­·­····
Edited by the lovely Sofibab.
········································­­·······································­·­····
► All content by Brackeys is 100% free. I believe that education should be available for everyone. Any support is truly appreciated so I can keep on making the content free of charge.
········································­­·······································­·­····
♪ Baby Plays Electro Games
teknoaxe.com/cgi-bin/link_code...

Опубликовано:

 

22 апр 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 594   
@talha9585
@talha9585 7 лет назад
These small but useful tutorials are best to watch.
@talha9585
@talha9585 7 лет назад
also, i would like to see switch animation
@coolboidoesstuff9828
@coolboidoesstuff9828 5 лет назад
@@talha9585 It is really not so hard, you can search up how to do it Edit: Never mind, it's harder than I thought
@dmudda90
@dmudda90 4 года назад
@@coolboidoesstuff9828 no making games is much easier than you think! .. :D
@coolboidoesstuff9828
@coolboidoesstuff9828 4 года назад
@@dmudda90 No I was talking about him asking for switching animation
@norriswu213
@norriswu213 4 года назад
@@dmudda90 "You should take this course on Udemy"
@Jamesthe1
@Jamesthe1 7 лет назад
You could also use modulo (aka the % operator) for the upward weapon switch. It would look like this: selectedWeapon++; selectedWeapon %= transform.childCount; If you don't know what modulo is, it basically gets the remainder from the division statement. You don't have to write a bunch of if statements that way. This saves a few lines and is actually quite efficient.
@bisharakhuri2504
@bisharakhuri2504 4 года назад
Tutorial unclear.. Accidentally created CS:GO
@BredMan_
@BredMan_ 4 года назад
lol
@sillyfella2009
@sillyfella2009 4 года назад
I hate it when that happens
@KlutzOfAMan
@KlutzOfAMan 3 года назад
Task Failed Successfully
@ShyGus
@ShyGus 3 года назад
That's litterally how good these tutorials are😂😂
@Mikelica69
@Mikelica69 3 года назад
@@KlutzOfAMan XD
@dexister6959
@dexister6959 7 лет назад
Your newest tutorials are so professional I can't imagine how long it takes to make a 2 minute video for you...
@light6602
@light6602 7 лет назад
Definitely should continue these smaller videos Brackeys!! Love them! I saw someone request an ammo system and I think that would be awesome! Along with a ui of course.
@chantendo2941
@chantendo2941 7 лет назад
your tutorials are super helpful!
@Brackeys
@Brackeys 7 лет назад
Thanks, glad you like it! :)
@neotomatoe7257
@neotomatoe7257 4 года назад
Yeah ;)
@SuperRalle123
@SuperRalle123 7 лет назад
As always, these small tutorials are really great! I would love to see one about animations :)
@Cyreides
@Cyreides 7 лет назад
I was going to need something similar like this for switching characters in my game, and this is perfect!
@zevac
@zevac 7 лет назад
you're helping me create a universe, brackeys. i love you
@redbepis4600
@redbepis4600 4 года назад
Did you finish? Can I buy it?
@zeroiq4737
@zeroiq4737 4 года назад
Red Bepis no lmao
@deraidos45
@deraidos45 7 лет назад
Very helpful as always. Been watching you since the first Survival Game tutorial
@Gathrey
@Gathrey 6 лет назад
Thanx Brackeys. Good efficient tutorial. Exactly what I was looking for. Keep it up! Looking forward to future tutorials.
@david35k
@david35k 4 года назад
Thank you! I really like your simple and clean tutorials! Very helpful
@chaosmastermind
@chaosmastermind 3 года назад
This is really useful and helpful. Thank you. Pretty much everyone that makes an FPS is going to need this.
@theodorescontras5569
@theodorescontras5569 7 лет назад
Great tutorial, got weapon switching working in my game before even having my coffee.
@obsidian295
@obsidian295 7 лет назад
Been following Brackeys since survival game, awesome channel !
@faisalsajjad7396
@faisalsajjad7396 7 лет назад
thx brackeys loving this series
@AshratAR
@AshratAR 7 лет назад
I thought the whole process was much more difficult than this!! But this tutorial made it all simple!!!! Thanks!!
@xiaobodong726
@xiaobodong726 4 года назад
Love your model, it’s so detailed
@renzocfn4669
@renzocfn4669 3 года назад
Best coding tutorial channel I've ever seen in this world!
@TheReal-Infinite
@TheReal-Infinite 7 лет назад
i'd love to see a continuation of the Multiplayer FPS Shooter with a Single Player Part of the Shooter
@ppnhzk
@ppnhzk 7 лет назад
Nice tutorial as always. As I want to free up memory as much as I can, I do the switch by instantiating the weapon at a placed spawn point every time it is selected. Also, I store all the functions in the weapon object, even key presses like fire. It was easier because of the differences in their behaviour. After watching your tutorial however I might go with your method as it seems much more fluid in the end, though it might get heavy with 10+ weapons, so some testing might be needed. Not sure how much extra load the inactive stuff means.
@OilRacki
@OilRacki 7 лет назад
Funny enough, I think I did 80% of this video on my own before seeing this. I think it just makes a lot of sense to do the way described here. It is good confirmation that I'd done things in a good way. There was one thing I did differently though.. I didn't have a "weapon holder" object, and just simply reference children below it, but I think that's just because of my game design. I have more weapons as children than the player can use, so I have something else to manage the weapons they're carrying and have armed. All in all, though, this is a great tutorial, and the method described here about the weapon holder is actually a really good idea. Thumbs up!
@ashwinanand4208
@ashwinanand4208 7 лет назад
can you connect this to the fps series please
@yurkagon
@yurkagon 7 лет назад
Which lighting effects (or image effects or something like this) are used in this project in this video?
@julianpizano5586
@julianpizano5586 6 лет назад
Great tutorial! but I have a problem... The weapons that I have attached to the character controller aren't part of a weapon holder game object. (they are just children of the main camera) if I try to child the weapons to an empty game object, the positions of the weapons change... this causes the weapon animations to change drastically. Is there a way to child the weapons to an empty game object (weapon holder) without changing the position of the weapons themselves??????? plz reply!
@TrifleWaffle
@TrifleWaffle 7 лет назад
thank you! I waited for this for so long!
@oSevenTV_
@oSevenTV_ 7 лет назад
How can I make the player run out of weapons? And is it possible to get some items in another hand?
@alimirbagheri453
@alimirbagheri453 2 года назад
You are just so awesome. words cant describe how you help. thank you brackey,s i miss you a lot. and hope that you are living your dream wherever you are.
@Jeamar
@Jeamar 5 лет назад
Hey! Was thinking.. I'm making a space shooter-like 2d game, mouse following control, and I want to make upgrades for the shots, and different weapons for my player (sorta like chicken invaders), how should I do that? I'm using a gunspot child for shooting, should I code for instantiate a different shoot in the gunspot, or should I instantiate a different gunspot for every level/kind of shot?
@vanthele5623
@vanthele5623 3 месяца назад
Thank you. The script is straightforward to understand
@bsi-blakkseriesinitiative7717
@bsi-blakkseriesinitiative7717 4 года назад
Can i use this tutorial to switch character models instead of gun models? Im trying to make a game that has player transformations. But the forms i want to change into, do not follow the base form when they change. I want all transformation forms to occupy the same space. Even when one form moves to a new location before transforming.
@AnuragJhaCreations
@AnuragJhaCreations 7 лет назад
i watched 1 video of yours and my mouse automatically went to subscribe this guy
@Kotzuo
@Kotzuo 7 лет назад
There's a little problem here (i dont know if is only for me) but when the ammo is over and the reload process start (same code as your video "Ammo & Reloading") if i change the weapon (dosnt matter if is scroll or number) and change again for the before ones, it will never reload. Its only for me? if its not, can you post a fixxed one?
@CAFcorey
@CAFcorey 5 лет назад
How would i go about making a weapon purchase system to go with this script? i somewhat have an idea, i have an empty game object in the scene called "weaponCache" where i will store all inactive weapons and then when i hit the trigger to purchase said weapon i would parent the weapon prefab into the weapons gameobject on my character. I just dont know how to go about scripting the part where it would replace the current weapon with the purchased one, and also i want to have a max of two weapons equipped at once.
@purpleguy9002
@purpleguy9002 5 лет назад
Thanks Brackeys! I love your videos!
@Kanal994
@Kanal994 7 лет назад
Great tutorials. Cheers !
@MaeveFirstborn
@MaeveFirstborn 7 лет назад
I have a problem. If an animation is playing as you switch the weapon (different weap switch script, same concept though,) it freezes it permanently. Except, other animations will play, but idle is now whatever position it was when the glitch occurs. How could I "reset" the animator?
@seifmustafa2004
@seifmustafa2004 7 лет назад
your tutorials are super awesome 🙆
@mrsparklepants5636
@mrsparklepants5636 7 лет назад
HE MADE IT ATLAST I LOVE YOU BRACKEYS YOU ARE THE
@brandonlilly5738
@brandonlilly5738 4 года назад
Question for you! For the other weapon scripts, did you inherit from the Gun script?
@salesbanglore1926
@salesbanglore1926 2 года назад
i have a error Assets\GunSwicher.cs(43,17): error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
@raphaelkrait7655
@raphaelkrait7655 5 лет назад
If i want every weapon to do a specific task, putting different scripts on each weapon will do the work?
@Oliver_TGB
@Oliver_TGB 6 лет назад
Really cool! I have an idea. How about you made a tutorial on how to make an ammo amount. In sense of being able to see how many bullets you can fire before there are none left and possibly a reloading animation.
@JustKatoh
@JustKatoh 7 лет назад
Thank you for the video, i have learned a lot
@bobbyfrost7573
@bobbyfrost7573 5 лет назад
When I run the program my WeaponHolder parent object is disabled at the start. I commented out calling the function SelectWeapon in void start and the WeaponHolder was enabled. Why would SelectWeapon be disabling my WeaponHolder object?
@lockedonbiome
@lockedonbiome 7 лет назад
Could you do a tutorial on enemy ai with shooting
@BlackMesaEmployee
@BlackMesaEmployee 6 лет назад
Boss Hog306 do you still need that tutorial? I’m considering making one
@sconosciutosconosciuto2196
@sconosciutosconosciuto2196 5 лет назад
@@BlackMesaEmployee you don't make video :(
@anshivvv.vfx99
@anshivvv.vfx99 4 года назад
@@sconosciutosconosciuto2196 he said he was considering. Duh?
@theasin_old
@theasin_old 3 года назад
@@BlackMesaEmployee please
@ranger10301
@ranger10301 2 года назад
@@BlackMesaEmployee do it
@artinmajidi1654
@artinmajidi1654 4 года назад
I had two animator components on my player, one for upper body and one for lower body. I made different controllers for each weapon and if that weapon is equipped, I simply switch animator controllers. Like this, I can do everything infinitely. And also, this took me a month to figure out. And another to do it.
@laurel8831
@laurel8831 7 лет назад
I love your thumbnails by the way
@SuperManIsDope
@SuperManIsDope 7 лет назад
Love the new thumb nails !
@doxel8691
@doxel8691 7 лет назад
wow! I didn't know the transform class implemented the IEnumerator interface that returned the children, good to know. thanks brackeys!
@StigDesign
@StigDesign 6 лет назад
how can you add a simple rotate down and up function when changing weapon? am thinking in stead of animating hands or the weapon, you Rotate.Lerp or something down and weapond change then rotates up :)
@TheAppeals
@TheAppeals 7 лет назад
Hello! Don't know if you/someone will answer, but I wonder how to make an inventory with the bottom bar which allows us to switch weapon, and then shoot! Any idea?
@FlyGuy8701
@FlyGuy8701 7 лет назад
I really like the new thumbnails.
@mlgsquirrel
@mlgsquirrel 3 года назад
i used this for switching attachments, but instead of scroll wheel its a button. great video man
@phoenx8868
@phoenx8868 7 лет назад
For Example, I want to make the player go and grab a gun on the floor to then keep it and switch it... All i need to do is put a Boolean (Something like Picked) and then if the bool is equal to true then proceed to execute the switching script?
@magnusm4
@magnusm4 7 лет назад
Simple, short and easy as it should be for programming
@migueldast8812
@migueldast8812 6 лет назад
Great job! You are awesome! I ask you a question becouse i need help with my game. If i have not pick up the weapons yet, how can i activate the script (of weapon switching) after that? NOTE: I have the weapons in trigger box for seleccion. Please i need to solve it! Thanks!
@user-qg1kd4zi3g
@user-qg1kd4zi3g 6 лет назад
How to make a weapon appear when you pick it up and not just a full set of weapons? Good lessons, thank you.
@chaosmastermind
@chaosmastermind 3 года назад
You would set the weapons all to inactive and then make a power up collectible that activates only one type of weapon for each.
@ThatRazzy
@ThatRazzy 2 года назад
Hey were you able to figure this out?
@lovishcool
@lovishcool 7 лет назад
thnx a loot brackeys, awesome video again...
@reginthesmith
@reginthesmith 4 года назад
I won't work for me the scroll wheel works but when I press one of the number keys key the value gos up but the weapon docent change
@krishnaveersingh4800
@krishnaveersingh4800 4 года назад
@Brackeys Hey ,Sci-Fi Weapons don't have textures and therefore they are not visible , can you help me adding textures
@gametips7627
@gametips7627 4 года назад
All the way first class tutorial. Love your tutorial
@blaizefar45
@blaizefar45 6 лет назад
Another Great Tutorial
@NiteHawkk123
@NiteHawkk123 5 лет назад
Amazing tutorial!
@achillesmoraitis7198
@achillesmoraitis7198 7 лет назад
Is it better to use the RidgedBodyFPSController instead of the regular FPSController?
@systematicloop3215
@systematicloop3215 7 лет назад
In the foreach statement in the SelectWeapon method, you could have simply said SetActive(selectedWeapon == i) instead of routing it to separate if statements.
@WeaverKnight777
@WeaverKnight777 7 лет назад
can we make an animation for weapon switching
@flashgames1273
@flashgames1273 7 лет назад
also shooting/aiming animations!
@davidenale17
@davidenale17 7 лет назад
Saad Tv yes will be nice to see it (and check if i'm doing it correctly)
@solomonlyons10
@solomonlyons10 7 лет назад
Saad Tv It's really really simple, I think a few really good videos on RU-vid goes over it. I feel like the only challenging part for a lot of people is the mecanim portion.
@JayAnAm
@JayAnAm 7 лет назад
Actually it isn't that hard, will put it to my list.
@remove6796
@remove6796 6 лет назад
switching with animations are easy you just need to make a default state anim and then make a sound fx play on awake and walla. you didn't understand did you? :(
@quanozoga8508
@quanozoga8508 3 года назад
I have a pick up system that uses a box collider and a rigid body but when I have them on the guns don’t work how do I make it to where they do work
@godhandzerozero4816
@godhandzerozero4816 7 лет назад
Nice vid. I was just wondering, how would you create someyhing like a mecha wherein you could swap the different armor pieces and weapons that changes the characteristics of the mecha. For example, changing the standard mecha feet to rocket propelled feet will make it faster.
@vikicoder
@vikicoder 4 года назад
Now that's called a awesome tutorial
@FeverDev64
@FeverDev64 4 года назад
Why is my update() function not being called every frame??? The melee game pbject is in the scene amd the finction is inside the main class!! Plz help me
@ildarildar1546
@ildarildar1546 5 лет назад
thank you Brackeys you rea lly helped me
@ItzNero69
@ItzNero69 6 лет назад
i need help. each weapon has a different damage. how can i make the damage be the one of the active weapon? please help! i can't figure it out!!!
@DeaMikan
@DeaMikan 7 лет назад
loved it! can you make a tutorial all about post processing effects on the camera!
@roguedagger1
@roguedagger1 4 года назад
I have an error, only assignment, call, increment, decrement, await, and new object expressions can be used as a statement . pls help
@fidolimp
@fidolimp 3 года назад
I'm having an issue where disabling the weapon permanently disable its shooting script. Any tips?
@pz579
@pz579 4 года назад
How do I get a grab weapon? Sorry my english, i am brazilian and i don't speak english very well.
@MsMAZMOE
@MsMAZMOE 7 лет назад
Can you make the tutorial on how to integrate Steam achievements in Unity3D? This is really confusing business.. I have no idea what I'm doing... And there are no videos about this topic. I'm in a complete loss..
@GoldenGamer26
@GoldenGamer26 6 лет назад
Best tutorial channel, why dislikes!?!
@PikBo100
@PikBo100 3 года назад
wrote the code step by step like in video but when i run the game..all weapons are enabled when selectedweapon index is 0 and when is 1 all weapons are disabled(((
@hantui8449
@hantui8449 7 лет назад
hey dee in the shooting with raycast video.....why i hit control Button its start shooting
@kaiser9321
@kaiser9321 7 лет назад
A better way for wrapping around would be using variable % number, I remember using it in another coding language but I'm not sure if it works in C#, get back to me on that, thanks
@brunoloverius5777
@brunoloverius5777 4 года назад
How can I get the standard assets today in 2019? I can't download anything except for custom packs :'( He uses them in nearly every single one of his videos :'(
@magnusm4
@magnusm4 7 лет назад
I like this way of making weapons best as it allows me to make each individual gun unique and not have to include every single stat on a single constructor file as some guns might be fired once or be selected as an ability so fire rate would be useless. Though i'm planning on having more than 30 or even 60 different weapons
@aryansatpathy2404
@aryansatpathy2404 5 лет назад
Hey brackeys... This thing won't update in HLAPI... I came here from the multiplayer fps tutorial.... N in my game, it won't change tge weapon in the server... Plz help
@SleakDarkRaven
@SleakDarkRaven 7 лет назад
Can you make weapon scope or zooming in for aiming?
@louislemur
@louislemur 3 года назад
HEy Guys i really need help right now! everytime before i switch a weapon i want to check if i already "own" this gun (i have a vending machine with guns) i gave a tag to all guns i bought. How do I Check before i switch if the next gun has this tag?
@LLITALKER
@LLITALKER 7 лет назад
Ingeniously and simply !!!
@jettmendoza7043
@jettmendoza7043 7 лет назад
when i switch to another weapon or in playing the game.. the gun is reloading.. please help
@frostymug3123
@frostymug3123 2 года назад
Great tutorial thank you!
@Random-uo8sp
@Random-uo8sp 5 лет назад
You have no right to be so good
@woofiewill
@woofiewill 6 лет назад
When you want to restrict an index to a range of numbers (like wrapping the index back to 0 when incrementing) it's almost always better practice to use modulus. Write `selectedWeapon = (selectedWeapon + 1) % transform.childCount` instead. This is a slight performance increase over using an if statement, and it's much more succinct. Even better would be this (I'll use some slight pseudocode): if (scrollUp) selectedWeapon++; else if (scrollDown) selectedWeapon--; selectedWeapon = selectedWeapon % transform.childCount; This way it's much simpler and you only need to apply modulus once to make sure the variable stays in your desired range.
@Dxpress_
@Dxpress_ 6 лет назад
I'm doing a similar thing, except instead of enabling/disabling weapons, I'm destroying the ones that are not being used and instantiating the one that is. Which method is better for performance? Enable/disable or instantiate/destroy? And does the performance factor vary depending on having a small number of weapons like 5 or so, and a large number like 100 or so? Edit: I should note that in my project, weapons cannot be changed on the spot; only when the player enters a safe zone.
@sconosciutosconosciuto2196
@sconosciutosconosciuto2196 5 лет назад
I think that destroying the weapons is better than disabled them
@Notchmods
@Notchmods 5 лет назад
Thanks a lot sensei brackeys
@SqualidsargeStudios
@SqualidsargeStudios 4 года назад
i wonder if the same code can be used for other things instead of weapon switching.
@cryora
@cryora 4 года назад
So the foreach (Transform weapon in transform) line searches only children transform, not grandchildren?
@szymonidesomco4974
@szymonidesomco4974 7 лет назад
How about insted of using a bunch of 'if' statements we use something like this: for (int iKey = 1; iKey
@emerickdorval3713
@emerickdorval3713 2 года назад
Barckeys you are my idole i like you so much i love your tutorials they teach me allot
@craze52
@craze52 6 лет назад
You are one of the best youtuber for scripting and youtube
@zedgamedev
@zedgamedev 6 лет назад
If you add animators to each weapon and switch between them then it messes with the Animations, Anyone have a fix for this?
Далее