Magic attacks!

I’m really curious on what’s the best possible way to code magic attacks?
I would really like to create my attacks in the form of objects if possible, so that I may use functions like:

var player : Player = attack.getAttacker;

What would be the best way to achieve this? can anyone give me some advice how I would detect when a spell hits another player?

Thank you!

Add a Collider to whatever it is you are shooting at (ie. enemies, other players, etc). You can use OnCollisionEnter to track when an object (the magic spell) collides with another object (the enemy).

If its not possible to use the code above can someone give me an example of how it’s usually done in unity?