#Applying Damage

1 messages · Page 1 of 1 (latest)

celest wharf
#

Is there any way to apply damage to the player during battle other than having them hit a note object? I want to code a special object that will damage the player if they come in contact with it that will spawn at a particular time during the battle.

sweet hound
#

alternatively you could track down the location of the player in the hierarchy (it would always be the same) and cache it from there if you'll be using the player a lot

fast jolt
#

I want to code a special object that will damage the player if they come in contact with it that will spawn at a particular time during the battle.

This sounds just like a note right? Except maybe you don't want it to move down the lane? In that case you could also just give the special object some of the note components and it would handle damage for you.

Otherwise calling the player damage method would work just fine too

celest wharf
#

Thanks for the help so far yall! When i try to use gameplayPlayer, my vs code can see the class just fine but when i import the code into unity via my dll and then try to compile the mod, it errors out and says that it cannot find that class. I also tried attaching the components of a note prefab to my object but when it collides with the player, and i confirmed that it does indeed collide, it does not affect the players health.

fast jolt
#

Do you want to share the code? There are a few weird reasons for code not compiling that you can normally work around.

Also, for the components solution - the components added to the note in unity is not the same as the components the notes in game actually have added to them. I can show you which class I mean later

fast jolt
#

man this spambot really hates me pasting code

#

sorry for the delay, your code looks reasonable, having trouble seeing any particular issue! The only thing that I haven't seen before is using FindObjectsOfType - I'd normally find the active player like this:

#

you get a picture because the bot hates code

#

maybe a silly thing to ask but it might be worth restarting unity if you've just updated your dll, this can also fix compilation issues.

celest wharf
celest wharf
fast jolt
#

super silly question - are you adding the c# scripts directly into your project or building a DLL?

celest wharf
fast jolt
#

and just to double check, you've been able to compile with a dll and some custom scripts, its just adding this particular script that caused issues?

celest wharf
#

VS Code has no problem making those calls and I don’t get any errors in unity either sometimes until I compile the mod

fast jolt
#

also out of interest are you able to expand the dll in the unity explorer window like pictured or does that cause errors too?

#

not 100% sure what's going on just trying to figure out if building the mod is the issue or it can't go in the unity project full stop

celest wharf
fast jolt
#

weird, this is not something I've personally experienced before. Not that I think this is the correct way around this but this solution should definitely work:

#

If you add a GameplayPlayer.cs file into the unity project and include a basic scaffold for the GameplayPlayer class (Just inherit it from MonoBehaviour, define a Damage function that takes in an integer does nothing), then your project should be able to compile.

^ Doing this allowed me to even include game classes as serializable fields of my custom scripts, which normally produces the same errors you are getting.

celest wharf
fast jolt
#

Oh, was there an object you were storing that I missed? Sorry I would've sent you to this snippet if I had seen that :(

But yeah what I outline above is essentially a workaround to that snippet, which is really only useful if you want to instantiate these in game classes rather than grab them by reference.

celest wharf