ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Turret Fire - Build a 2D Tower Defence Game in Unity #5

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 เม.ย. 2023
  • Learn how to make a 2D tower defence game using Unity. In this video, we apply a Shooting mechanic to our Turrets and then destroy our Enemies in our 2D Tower Defense game built in Unity.
    Next Video: • Building Towers - Buil...
    Previous Video: • Turrets - Build a 2D T...
    Playlist: • 2D Tower Defence Tutor...
    The source code can be found on Patreon (link below)
    // SUPPORT THE CHANNEL
    / muddywolf
    // JOIN THE COMMUNITY DISCORD!
    / discord
    // PLAY MY DAMN GAME ALREADY?
    play.google.co...
    // WEB DEV CHANNEL
    / tylerpotts
    #UnityTutorial #2D #TowerDefense

ความคิดเห็น • 47

  • @MuddyWolf
    @MuddyWolf  ปีที่แล้ว +19

    Are you enjoying this series so far? I know I am!

    • @kobzyy
      @kobzyy ปีที่แล้ว +3

      yea

    • @mininim08
      @mininim08 ปีที่แล้ว +2

      Yeah I love this series. Iv'e been looing for a tutorial like this for weeks😊

    • @MX1732
      @MX1732 ปีที่แล้ว

      yes!!😃

    • @flolifes
      @flolifes 11 หลายเดือนก่อน

      No. What are you doing??? you jump between 50 parts of DIFFERENT code instead of working on one part. Why are you assigning variables throughout, you should assign them all at the start. You ignore precision because it's 'fun'????????? What on earth are you doing, you should NOT be let in proximity to a computer. On top of this, you have ZERO understanding of editing, copying as soon as you do something is NOT a good idea. You are speaking at a volume of 3 DECIBELS. Talk louder and learn how to make a tutorial before claiming to be SO advanced you can make a n11 PART tutorial where each part gets NOTHING done.

  • @Kottenbruch
    @Kottenbruch 13 วันที่ผ่านมา

    I really enjoy your series, though you are really fast! And here ´n there i really don´t understand how things work or how to "learn" that properly to remember it and transfer to another project. I have a lot of coding experience, but those gaming scripts are sth different :D. I´m just following along your nice tutorials, let´s see in the end.

  • @mitkorx3270
    @mitkorx3270 ปีที่แล้ว +3

    Very cool series

  • @y.u.i.
    @y.u.i. ปีที่แล้ว +2

    Thank you so much for this video. You really saved my project

    • @MuddyWolf
      @MuddyWolf  ปีที่แล้ว +1

      Happy to help!

  • @timshymkus547
    @timshymkus547 6 หลายเดือนก่อน +2

    this has been great! Is there a DestroyBullet command when they miss? I don't see that...but they are adding up ;0

  • @Caden_is_cool
    @Caden_is_cool ปีที่แล้ว +2

    I keep getting an error that says Assests\Code\Scripts\Bullet.cs(30,9): error CS0103: The name ‘other’ does not exist in the current context

    • @zhorik916
      @zhorik916 ปีที่แล้ว +1

      Me too bruh, have you managed to fix this? If yes say how plz

    • @ymmuy3065
      @ymmuy3065 ปีที่แล้ว +1

      check the input parameter name. It might be "collision" instead of "other"

  • @blacknwhite1313
    @blacknwhite1313 2 หลายเดือนก่อน

    thankyou respected brother

  • @blacknwhite1313
    @blacknwhite1313 2 หลายเดือนก่อน

    i didnt understood the SetTarget Function can anyone teach me thanks

  • @yypsiloolo
    @yypsiloolo ปีที่แล้ว +2

    I chose a different Bullet design, which has an elongated shape. How can I rotate my bullet in the right direction when it is fired right at the beginning? For this you only have to retrieve the rotation value from the turret and transfer it to the bullet, but how exactly? Otherwise it hits the Enemy with the elongated side instead of the front, pointed side.

    • @WideWalkinMenace
      @WideWalkinMenace 11 หลายเดือนก่อน +7

      Might be a bit late, but the answer is actually rather simple. All you have to do on the bullet script is set the rotation of the bullet to the direction vector: transform.up = direction;

  • @itsagamertv6252
    @itsagamertv6252 ปีที่แล้ว +2

    Its funny how fucked up my code is even though i am following your vids. Thanks Regardless

  • @jameshylands4175
    @jameshylands4175 ปีที่แล้ว +2

    Great Videos very informative but I have one small issue when the bullets collide with the enemies they do not take any damage. The hitpoints dont go down and neither the bullet or the enemy disappear. Any help would be appreciated

    • @jameshylands4175
      @jameshylands4175 ปีที่แล้ว

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class BulletScript : MonoBehaviour
      {
      [Header("References")]
      [SerializeField] private Rigidbody2D rb;
      [Header("Attributes")]
      [SerializeField] private float bulletSpeed = 5f;
      [SerializeField] private int bulletDamage = 1;
      private Transform target;

      public void SetTarget(Transform _target)
      {
      target = _target;
      }

      private void FixedUpdate()
      {
      if(!target) return;

      Vector2 direction = (target.position - transform.position).normalized;
      rb.velocity = direction * bulletSpeed;
      }
      private void OnCollisionEnter2D(Collision2D other)
      {
      other.gameObject.GetComponent().TakeDamage(bulletDamage);
      Destroy(gameObject);
      }
      }
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class Health : MonoBehaviour
      {
      [Header("Attributes")]
      [SerializeField] private int hitPoints = 2;
      public void TakeDamage(int dmg)
      {
      hitPoints -= dmg;
      if (hitPoints

    • @hugosmith7952
      @hugosmith7952 ปีที่แล้ว

      @@jameshylands4175 Not sure if you're still having this issue but could potentially be due to collision boxes not being assigned correctly or that the objects are different heights in the z axis. This is what caused it for me

  • @mayzavan
    @mayzavan ปีที่แล้ว +1

    I somehow have a trouble, even though i created bullet layer and assigned it to bullet and in project setting physics 2D i have ticked off everything besides Enemy, the bullet still hits the wall. Im trying to figure it out, since 40 minutes or so but i have no clue why

    • @mayzavan
      @mayzavan ปีที่แล้ว

      Like it doesnt destroy itself but it stops

    • @morganp7238
      @morganp7238 2 หลายเดือนก่อน

      same problem

  • @jhonatancruzreyes4711
    @jhonatancruzreyes4711 ปีที่แล้ว +1

    I do the step in the min 11:28 but the bullet stuck in the floor somebody now why?

    • @morganp7238
      @morganp7238 2 หลายเดือนก่อน

      I had the same problem because I had written...
      _target = target
      ... instead of...
      target = _target

    • @jhonatancruzreyes4711
      @jhonatancruzreyes4711 2 หลายเดือนก่อน

      @@morganp7238 Send the complete script i renember the error was easy to fix

  • @alleloof
    @alleloof 10 หลายเดือนก่อน

    My firingposition is fixed in place where i place it. I does not move accordingly to the turret. Fix?

    • @darkiphoenix2072
      @darkiphoenix2072 9 หลายเดือนก่อน

      you put the firingpostion under the rotationpoint in the hierarchy

  • @tophertime3104
    @tophertime3104 11 หลายเดือนก่อน

    For some reason my bullet is meeting the transform of the enemy, but the game object isn't destroying upon colliding with the enemy...

    • @tophertime3104
      @tophertime3104 11 หลายเดือนก่อน

      Ah, for some reason my OnCollisionEnter2D script will only work if I add a Boxcollider2D component to my prefab, then exclude the default layer... even though I changed all of the settings :o at least it's working... for now haha

  • @mendo1522
    @mendo1522 ปีที่แล้ว

    3:15 JB Bloc Boy on the console

  • @dlittlehoboapps1438
    @dlittlehoboapps1438 7 หลายเดือนก่อน +1

    I keep getting this NullReferenceExxception object reference not set to an instance of an object Bullet. OncollisionEnter2D

  • @gabrielchapman9364
    @gabrielchapman9364 ปีที่แล้ว

    I am having a problem where when the bullet is fired, it just stays in the spot it was fired from, any idea why?

    • @paulsiddall6074
      @paulsiddall6074 ปีที่แล้ว

      I had this issue, it was resolved by going through the instructions at 11:10 on the video. While I thought I had changed the Layer Collision Matrix it hadn't saved for me

    • @gabrielchapman9364
      @gabrielchapman9364 ปีที่แล้ว

      @@paulsiddall6074 i fixed it but now the bullet is not colliding with the enemy either 🙃

    • @temuriko1226
      @temuriko1226 3 หลายเดือนก่อน

      Can someone help I couldn’t attach reagedbody to bullet

  • @playersinexile72
    @playersinexile72 ปีที่แล้ว +3

    If I comment the following out the game seems to work fine,
    private void OnCollisionEnter2D(Collision2D collision)
    {
    //collision.gameObject.GetComponent().TakeDamage(bulletDamage);
    Destroy(gameObject);
    }
    however, when I run the game with the code I get the following:
    NullReferenceException: Object reference not set to an instance of an object
    BulletScript.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/Code/Scripts/BulletScript.cs:32)
    It happens as soon as the bullet spawns.
    It happened with Other instead of collision as well.
    Any ideas?

    • @writewitholi
      @writewitholi 2 หลายเดือนก่อน

      I am having this problem as well. It seems like Unity is having trouble identifying the target as the gameObject? The fix that Visual Studio is recommending is that I add a void variable "v" but it seems like the recommendation will only create more problems. I am not sure how to fix this. I would appreciate an update.

    • @robertmcdougall1144
      @robertmcdougall1144 2 หลายเดือนก่อน

      Curious? What does your Health script look like?

    • @writewitholi
      @writewitholi 2 หลายเดือนก่อน

      @@robertmcdougall1144
      public class Health : MonoBehaviour
      {
      [Header("Attributes")]
      [SerializeField] private int hitPoints = 2;

      public void TakeDamage(int dmg)
      {
      hitPoints -= dmg;
      if(hitPoints

    • @writewitholi
      @writewitholi 2 หลายเดือนก่อน

      @@robertmcdougall1144 public class Health : MonoBehaviour
      {
      [Header("Attributes")]
      [SerializeField] private int hitPoints = 2;

      public void TakeDamage(int dmg)
      {
      hitPoints -= dmg;
      if(hitPoints

    • @writewitholi
      @writewitholi 2 หลายเดือนก่อน

      @@robertmcdougall1144 public class Health : MonoBehaviour
      {
      [Header("Attributes")]
      [SerializeField] private int hitPoints = 2;

      public void TakeDamage(int dmg)
      {
      hitPoints -= dmg;
      if(hitPoints