This should be a reasonably straight forward lecture but I’m curious to learn if anyone is still struggling with creating arguments in their methods and passing in the values from another class.
Hello Rick, I just notice that (well in my case) I add a sphere to my enemy with a sphere collirder on it so if I shoot it offcurse enemy never got hit at all, I just disabled it and all was fixed. Just in case someone had trouble on it
Hi, Rick, I pasted your code from commit an I still get the error : object reference not set to an instant of an object. I can shoot the platforms, floor and enemy but not the sky, houses or pillars
Can you please help me with this.
Thank you
That kind of error usually means that you have connected the wrong reference in the inspector. Check that you have dragged or selected an object from your hierarchy and not a prefab from your file directory. Hopefully its something as simple as that.
Thanks Rick,
I was testing the enviroment and I noticed that I can pass through the objects (for some reason) and that gave me a hint, I added box collider and it worked, no more errors except when I shoot in the sky, hm.
Btw, the courses are great, realy helpfull, keep up the good work.
Glad you got it figured out!
Make sure you add the prefabs in the Standard Assets pack to the Sandbox scene, not the models as the models do not have the colliders attached to them.
Why aren’t we using the BroadcastMessage method to notify a target if it’s been damaged as this is a more flexible way of applying damage to an object that has been struck?
private void Shoot()
{
RaycastHit hit;
if(Physics.Raycast(FPCamera.transform.position, FPCamera.transform.forward, out hit, range));
{
Debug.Log("I hit this thing: " + hit.transform.name);
hit.transform.BroadcastMessage("Damage", weapon_damage, SendMessageOptions.DontRequireReceiver);
}
}
If an object can’t be damaged then I don’t have to implement the Damage receiver and doing things this way means that the code sending the Message does not have to know about the thing receiving the damage.
public void Damage(float amount)
{
hitpoints -= amount;
print("I am Damaged");
}
Oh buddy, that was an adventure. If anyone is following along I refactored a jillion things (it feels like) today. I wrote about it here:
http://devlog.merlinsbeard.net/2020/10/21/refactorland/
Hi Rick
i added a sound effect on my enemy via Wwise but when i eliminate my enemy the sound effect is still there. Any idea how to fix that?
Thank you
Hello Rick
I also wanted to damage enemies with particles as well. I tried calling the DealDamage(damage) method inside onParticleCollision in EnemyHealth, but I got an error saying that the name ‘damage’ does not exist in current context. I went back to the script and declared Weapon shot as variable from the Weapon script and didn’t know what to do next. Can someone help?