I am new to unity, scripting and here too. So if any mistake in my post please excuse me.
I am trying to create a 2D game., Where we have several enemies and our player hit them with bullets and so do them killing player with bullets. Issue I am facing is if I keep the projectile script same for players and enemies, then enemy bullets will kill other enemies but player. I can create another projectile script with player tag in ontriggercollider. But is there a way I can use same script for both.
What I was thinking of is to use tags of the collider object and that of the gun or muzzle that bullet instantiates at and using these to decide which game object will take hit. Now I am not able to get the tag of the muzzle gameobject from gun script in the projectile script. Could someone help me witb this. Thanks in advance.
You can do multiple things, you can use tags as you’ve said, but you can also give the enemy’s bullet a different layer with bullet.gameObject.layer, and adjust the collision matrix so that the EnemyBullet layer collides only with the Player layer, and the PlayerBullet layer collides only with the Enemy Layer, you can generalize your layers tho, this way is more performant because you’re not just ignoring the collision, the collision does not even happen.
Thanks for the help and I sincerely apologise for the delay in conveying my regards to you. Your suggestion did work. Thanks a lot. You guys are amazing. Newbies like me will not feel alone when guys like you are there.