MODULAR WEAPON SYSTEM in Unity in Under 4 Minutes
HTML-код
- Опубликовано: 9 авг 2022
- In this video, I show you how to make an easily customizable gun/weapon system in Unity.
Join my Discord! ► / discord
::More Resources::
How to make a smooth FPS Character Controller ► • SMOOTH FIRST PERSON MO...
? Operator ► docs.microsoft.com/en-us/dotn...
Raycasting ► docs.unity3d.com/ScriptRefere...
UnityEvent ► docs.unity3d.com/ScriptRefere...
C# Properties ► docs.microsoft.com/en-us/dotn...
Code is in the discord for those who need it! (Link in the description)
I can't find the code
@@MonkeMan71 go to #code-archives in the discord after getting the rewction role
@@Rytech_Devthanks
Wonderful tutorial, I enjoyed that you took a second to explain each step.
YOU ARE A LEGEND!!! THANK YOU SO MUCH!! ive been trying to learn how raycasts work and this is so simple and easy to follow. Very underrated!!
I'll tell ya what, this is a really solid video. Good job mate
I don't think I deserve this Tutorial, So much info in so little time!
So Helpful! ❤
I never knew about a Unity Event :/ thanks man i can do alot that just guns with this new info bro.
UR A LIFE SAVER THANK YOU SO MUCH!!!
hey just wondering how could u add muzzle flash and damage indicators when shooting enemies?
very helpful thanks👍👍
Thanks soooo much♥
anyone know why there wouldnt be a shoot() function under the damage gun tab on the event handler, as shown at 2:50?
I did that wrong
Go to the Damage Gun script and make it to public instead of private in the shoot function
Great!
You are a gentlemen and a scholar
why am i getting a stack over flow error
Please make a video how to add particles to it
hey there, where can we download the code for copy and paste? i have some errors and dont wanna debug them all
From his discord server. But it actually have a bit of errors, so stay attentive!
tried this, didint work- tried joining the discord to see the code- didint work.. it just says theres an object refrence not set to an instance of an object.. NVM! Set your camera to maincamera in its tags, that should do the trick!
Cool tutorial, if you could add some chill music maybe. That would be nice in your future videos ^^
I whould love it if i could see the ammo :)
this is very clever, I am using this method in godot!
can i have the entity script
while making the gun damage I noticed that there was an error on enemy.Health -= Damage; does anyone know what is wrong, I am new to unity.
make a script for entitiy or remove line
Timestamp: ~2:25. Hey, I chose to use the "Damage Gun" version, and I'm getting an error that says: error CS0246: The type or namespace name 'Entity' could not be found (are you missing a directive or an assembly reference?).
nvm i figured it out :P
@@lasernugg How?
alright, all you need to do, is create a new script, and name it as "Entity". And just copy the code from the video
@@whysl I’m pretty sure you just do both gun versions, that fixed it for me I believe
It says entity could not be found
I don’t understand what is going on. My script is working fine except that my gun instantly kills my enemy even though it’s damage and the health are both the exact same as the video.
Where you ever able to figure out the issue? I'm getting the same thing.
same here@@sushiman3817
if you are still having trouble you have to change the fire cool down on the gun@@sushiman3817
Isn’t that how it works if you do the same amount of damage to an enemy and it has the same heath it should be dead? Right?
I can't find "shoot()" in OnGunshoot from 'gun' script
did you find it?
You've likely not named things correctly. The intellisence will direct you, hit alt plus enter over it, I think thats the command that should help you.
Bro mine shows error idk why I did it all perfect
Is the script and in the script the same name?
can you give me the script for the entity class plsss
its giving me this error StackOverflowException: The requested operation caused a stack overflow.
entity.get_Health () in :0
this does not works for me :(
Script??
Holy fucking shit
😁😄😃😃🙂🙃😉🙃😉😉🥵🤢🤢🤢🧐😕🥶🥸🥺🥺🥸😧😰😥😭😭😮😱😱☹🙁😵💫
@@Rytech_Dev 1
using System.Collections.Generic;
using UnityEngine;
public class Entity : MonoBehaviour
{
[SerializeField] private float StartingHealth;
private float health;
public float Health
{
get
{
return health;
}
set
{
health = value;
Debug.Log(health);
if (health
Very easy to understand for begginers, but the code isn't very clean and it might teach them bad habits
aint no way in hell im typing all that. put it in the description.
All tutorial code is in my discord server
@@Rytech_Dev Doesnt work, its blocked off for me, says im not allowed in the channels for the code
theres half an hour of my life i spent that im never getting back. idk wtf all these people are talking abt
jk boo i just needed to add a collider to the camera thx
lol
Not so much a weapon system as it's just how to create a single gun.
year late but you clearly missed the point
Another Dude that thinks he can code but just wastes peoples time, there is not health reference code full of errors, if you need a tutorial look for someone more knowledgeable. SKIP this GUY
nah this works
it works. check if your code is right lol
what unity version are u using
@@cattebayo
Hey, @Rytech. I can't figure out whats wrong with my dmg script. I've check 4 times and still cant figure out what it is.
Here is my error code: NullReferenceException: Object reference not set to an instance of an object
DamageScript.Shoot () (at Assets/DamageScript.cs:18)
Please try to respond in the next 3 days as for I will probably have quit later than that. Since your tutorials are easy to learn and actually have given me some knowledge of C#
Go to paste bin, and poste your code there, and put the link here, maybe i can help
@@tughloksiddiquee1714
I can't at the moment, so i'll just show you it here.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DamageScript : MonoBehaviour
{
public float Damage;
public float BulletRange;
private Transform PlayerCamera;
private void Start()
{
PlayerCamera = Camera.main.transform;
}
public void Shoot()
{
Ray gunRay = new Ray(PlayerCamera.position, PlayerCamera.forward);
if (Physics.Raycast(gunRay, out RaycastHit hitInfo, BulletRange))
{
if (hitInfo.collider.gameObject.TryGetComponent(out Entity enemy))
{
enemy.Health -= Damage;
}
}
}
}
@@Noalogy are you sure you referenced everything? the error says that you haven't referenced something on line 18 of your "DamageScript"
i know this is 10 months late, but I just solved the same problem for anyone else; the camera that your player sees with must be tagged as the maincamera in the inspector menu, thats what the damagegun script is accessing
using System.Collections.Generic;
using UnityEngine;
public class DamageGun : MonoBehaviour
{
public float Damage;
public float BulletRange;
private Transform PlayerCamera;
private void Start()
{
PlayerCamera = Camera.main.transform;
}
public void Shoot()
{
Ray gunRay = new Ray(PlayerCamera.position, PlayerCamera.forward);
if (Physics.Raycast(gunRay, out RaycastHit hitInfo, BulletRange))
{
if (hitInfo.collider.gameObject.TryGetComponent(out Entity enemy))
{
enemy.Health -= Damage;
}
}
}
}
damage gun