Unity Tutorial (2021) - Making the Player Attack

Ғылым және технология

In this Unity Beginner Tutorial, we'll add some Attacking Capability to our Player :)
== UNITY VERSION IN THIS TUTORIAL ==
Unity 2020.3.13f1 LTS
== UNITY PLAYLIST & SUBSCRIBE ==
📃 The Unity Playlist easily accessible here: url.kaupenjoe.net/ytUnity2021...
🔴 Don't forget to subscribe for more awesome tutorials: url.kaupenjoe.net/tutorials/sub
== ASSETS & DOWNLOAD LINKS ==
GitHub Repo: github.com/Tutorials-By-Kaupe...
Gist: url.kaupenjoe.net/yt31/gist
Unity Package: url.kaupenjoe.net/yt31/package
== TIMESTAMPS ==
0:00 Intro
0:30 Setup
0:51 PlayerAttack Script
2:38 The Attack Area
4:56 Quick Overview
5:56 Demonstration
6:53 Outro
== TAKE A LOOK AT MY COURSES WITH COUPON CODES ==
▶️ NEW Forge Modding with Minecraft 1.20.X:
url.kaupenjoe.net/CourseForge...
▶️ Learn Forge Modding with Minecraft 1.18:
url.kaupenjoe.net/CourseForge118 *
▶️ Learn Fabric Modding with Minecraft 1.18:
url.kaupenjoe.net/CourseFabri... *
▶️ Complete and Roblox Lua Game Development:
url.kaupenjoe.net/RobloxCoupon *
== SOCIALS ==
Discord: / discord
Personal Twitter: / kaupenjoe
Instagram: url.kaupenjoe.net/tutorials/i...
Facebook: url.kaupenjoe.net/tutorials/f...
Twitter: url.kaupenjoe.net/tutorials/t...
TikTok: url.kaupenjoe.net/tutorials/t...
Written Tutorials: url.kaupenjoe.net/tutorials/blog
== LICENSE ==
Source Code is distributed under the MIT License. Additional Licenses for other assets can be seen below or in the accompanying CREDITS.txt on download.
== ADDITIONAL CREDITS ==
Knight (in Video and Thumbnail) from o_lobster, entire pack from here:
o-lobster.itch.io/simple-dung...
Outro Musik by Kevin MacLeod:
"That's a Wrap" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 3.0
creativecommons.org/licenses/b...
== AMAZON AFFILIATE LINKS ==
Amazon Referral [US]: url.kaupenjoe.net/amazonref/us *
Amazon Referral [UK]: url.kaupenjoe.net/amazonref/uk *
Amazon Referral [DE]: url.kaupenjoe.net/amazonref/de *
== AFFILIATE DISCLAIMER ==
* Some of the links and other products that appear in the video description are from companies which I will earn an affiliate commission or referral bonus from or are my own products. This means that if you click on one of the product links, I’ll receive a small commission or additional kickback without any additional cost for you. This helps support the channel and allows me to continue to make videos. Thank you for the support!
== HASHTAGS ==
#UnityTutorial #Unity #GameDevelopment #Kaupenjoe

Пікірлер: 61

  • @zamcham
    @zamcham Жыл бұрын

    If your enemy doesn't receive damage after the first hit, set Rigidbody sleep mode to "Never Sleep" and that should fix it

  • @CokeVoAYCE

    @CokeVoAYCE

    Жыл бұрын

    thanks. i was just coming back to this video to ask about this particular problem.

  • @nighmarer9011

    @nighmarer9011

    7 ай бұрын

    Thanks a lot

  • @highlyunjust

    @highlyunjust

    2 ай бұрын

    can you explain why we need to set it to "Never Sleep" for it to work?

  • @romanretake
    @romanretake2 жыл бұрын

    Love your tutorials, they are straight to the point, quick, and very informative keep up the good work man!!

  • @ModdingByKaupenjoe

    @ModdingByKaupenjoe

    2 жыл бұрын

    Thank you so much, Roman. That was my goal with these :)

  • @playbehnder
    @playbehnder Жыл бұрын

    Thank you , this is very helpful!

  • @angiebui2887
    @angiebui28872 ай бұрын

    Thanks! Great video!

  • @Mallard_Games
    @Mallard_Games3 ай бұрын

    great tutorial!!

  • @giladbarilan310
    @giladbarilan3109 ай бұрын

    thank you so much

  • @mrri5155
    @mrri5155 Жыл бұрын

    Thanks man, most of the tutorials I see are the simplest ones

  • @ModdingByKaupenjoe

    @ModdingByKaupenjoe

    Жыл бұрын

    Glad you like them! 😁💙💙

  • @SERBIANUGANDANKNUCKLES
    @SERBIANUGANDANKNUCKLES Жыл бұрын

    i got an error on 3:54 Severity Code Description Project File Line Suppression State Error CS0619 'Component.collider' is obsolete: 'Property collider has been deprecated. Use GetComponent() instead. (UnityUpgradable)' Assembly-CSharp C:\Users\stefa\2d marine\Assets\assets\AttackArea.cs 10 Active

  • @CokeVoAYCE
    @CokeVoAYCE Жыл бұрын

    does anybody have a link to another tutorial that can add attack and knockback when hitting anywhere?

  • @dymian6762
    @dymian6762Ай бұрын

    I have a quick question i hope u will see it fast but do you mby know what can be the problem i used ur code to health and everything was awesome i added attacking and its not working . Did u do something else like in idk movement what can cause this?

  • @apricodegames
    @apricodegames11 ай бұрын

    Ty man.

  • @byee_66
    @byee_66 Жыл бұрын

    How do I add an attack animation to this?

  • @ayoubghram376
    @ayoubghram3762 жыл бұрын

    thank you

  • @ModdingByKaupenjoe

    @ModdingByKaupenjoe

    2 жыл бұрын

    You're welcome

  • @user-oq5tj7dd8m
    @user-oq5tj7dd8m5 ай бұрын

    Hey I have a background with a layering system, sorry if this is stupid but this is my first game im making with no experience, but the polygon collider 2d wont show up for the attack area thing, could someone please help me out here. I know its probably to do with layers but changing the position in the layer doesnt work

  • @user-oq5tj7dd8m

    @user-oq5tj7dd8m

    5 ай бұрын

    nvm solved it

  • @Squeezy911
    @Squeezy9112 жыл бұрын

    Great tutorial! But i have 1 question, when i stay motionless, after 1 attack enemy do not take damage anymore from my attacks

  • @user-vb6hg2cc9m

    @user-vb6hg2cc9m

    2 жыл бұрын

    i have the same problem, how to fix it bro?

  • @peterruuska6673

    @peterruuska6673

    2 жыл бұрын

    Having the same problem, any fix available?

  • @eliassafo6699

    @eliassafo6699

    Жыл бұрын

    same

  • @eliassafo6699

    @eliassafo6699

    Жыл бұрын

    Solution set Rigidbody sleep mode to never Sleep

  • @Chylord

    @Chylord

    Жыл бұрын

    thanks for the info, was having the issue and didnt know how to fix it!

  • @user-tp5yq4uh2d
    @user-tp5yq4uh2d Жыл бұрын

    NEED HELP, everything works with the attack area and damage etc. The problem i have is I am making a 2d side scroller, and the attack area is on the right side of my character when he is facing right, but when i move my character and he faces left, the attack area stays on the ride side of my character no matter which way he is facing. I need the attack area to go on the side that my character is facing not just to stay on the right side.

  • @bluegarrett

    @bluegarrett

    4 ай бұрын

    My problem now, can't seem to flip colliders..

  • @trollofthedungeon9196
    @trollofthedungeon91962 жыл бұрын

    This was a great tutorial! but I am getting an error. It says I'm using health like an type even though it is a variable. Do you know how to fix this?

  • @ModdingByKaupenjoe

    @ModdingByKaupenjoe

    2 жыл бұрын

    Hmm, very strange. Can you send the exact wording of the error, because there might be some nuance missing :)

  • @zoray5143

    @zoray5143

    2 жыл бұрын

    Correct me if I am wrong, but are you watching this video without having watched this video? kzread.info/dash/bejne/pJl7ktmnfLDVg9Y.html I think the Health component won't exist until you have this health system set up for attacking to matter.

  • @mattiazanini3779
    @mattiazanini37792 жыл бұрын

    Hi, I followed the whole video and I basically copied everything, adapting it to my project, but one thing I noticed is that OnTriggerEnter2D works only once, let me explain, the character approaches the enemy, attacks him and does them, as per the tutorial, damage, however if the player stands still and attacks the enemy again, in the position in which he was, since he has not moved, OnTriggerEnter2D is not recalled, thus resulting in that the player does not inflict damage on the enemy, however if the character moves even one millimeter, remaining in the area for there to be a collision, the function is called correctly and the player deals damage to the enemy. Now would anyone know how to solve this problem? I've been banging my head for days without having taken a step forward.

  • @hoshikun6605

    @hoshikun6605

    2 жыл бұрын

    Same around here :/ Haven't found out either

  • @hoshikun6605

    @hoshikun6605

    2 жыл бұрын

    Also if I child the game camera to the character when attacking the camera deactivates

  • @mattiazanini3779

    @mattiazanini3779

    2 жыл бұрын

    @@hoshikun6605 i think is better to create a component for the camera, for follow the player, It isn't very difficult, and i think is the best solution instead of child the camera to the player

  • @NikolasPapadakis

    @NikolasPapadakis

    Жыл бұрын

    Solution set Rigidbody sleep mode to never Sleep

  • @NikolasPapadakis

    @NikolasPapadakis

    Жыл бұрын

    @@hoshikun6605 Solution set Rigidbody sleep mode to never Sleep

  • @jonathanstrong9764
    @jonathanstrong976411 ай бұрын

    Help when i type collider.GetComponent() it gives an error for the Health saying it doesnt exist

  • @ModdingByKaupenjoe

    @ModdingByKaupenjoe

    11 ай бұрын

    Then whatever game object you're hitting does not have the Health script attached as a component! 🤔

  • @randorandom9494
    @randorandom949410 ай бұрын

    So what if i have multiple types of enemies with different behaviours? GetComponent doesn't work because all these scrips need to have different names

  • @ModdingByKaupenjoe

    @ModdingByKaupenjoe

    10 ай бұрын

    You could make one main Enemy script and have others that derive from that script. Or alternatively you can have an Enemy script which has a field/reference to something called EnemyBehaviour which could be an interface. You could then create multiple scripts that implement the EnemyBehaviour and just plug them into the specific enemy. This would also allow to switch out behaviours on the fly :) Hope this helps :)

  • @randorandom9494

    @randorandom9494

    10 ай бұрын

    @@ModdingByKaupenjoe yeah i learned inheritance and created a takedamage function in the main script, that works

  • @mongooserat7976
    @mongooserat7976 Жыл бұрын

    How do you make it so only the enemy takes damage when you hit D

  • @Enderia2

    @Enderia2

    Жыл бұрын

    make sure the attack collider doesn’t overlap your own, is my best guess

  • @Solbast
    @Solbast2 жыл бұрын

    I need the code

  • @ModdingByKaupenjoe

    @ModdingByKaupenjoe

    2 жыл бұрын

    All the code from the tutorial is linked in the description. Either in the github repository or in the gist!? 🤔

  • @panaritchumni4359
    @panaritchumni4359 Жыл бұрын

    i did it and when i hit i disappear ;w;

  • @ModdingByKaupenjoe

    @ModdingByKaupenjoe

    Жыл бұрын

    Probably in the attack method instead of SetActive on the attack area, you're probably calling it on the Player itself. That's my best guess 😅

  • @ModdingByKaupenjoe
    @ModdingByKaupenjoe2 жыл бұрын

    FIRST!!!!11 :P

  • @ivanzivkovic9630
    @ivanzivkovic96303 ай бұрын

    Ty man not working

  • @engineergaming3830

    @engineergaming3830

    Ай бұрын

    you need to make the health first

  • @XulinBr
    @XulinBr5 ай бұрын

    HELP

Келесі