R
R
RandomProgrammer2021-09-25 19:56:21
Unity
RandomProgrammer, 2021-09-25 19:56:21

How to implement the code?

I have different scripts on different objects, but they have the same Action method (implemented differently in different scripts, just the same name). I want to cast a ray on an object through Raycast and call its Action method. But then I need to know the name of the particular script. What should I do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2021-09-25
@RandomProgrammer

Read about interfaces in c#. Here they are exactly for this.
And yes, GetComponent works with interfaces.

R
RandomProgrammer, 2021-09-25
@RandomProgrammer

object.sendmessage("Action"); Solved my problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question