N
N
NickName73312018-05-07 21:09:54
C++ / C#
NickName7331, 2018-05-07 21:09:54

Unity (C#) - How to check if a specific script is attached to an object?

There is an object to which a certain script is attached, and there is another object with a script. When the first object collides with any other object, you need to check if the other object has that script attached to the second object. How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Basmanov, 2018-05-07
@NickName7331

Use the OnCollisionEnter event and the GetComponent method .

P
Philyaa3, 2021-09-27
@Philyaa3

if(GetComponent<script name>()){
//Your script
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question