Harter
1
Hello
Is there any other way to kill script by itself:
public class MySuperAwesomeScript : MonoBehaviour {
...
Destroy(GetComponent<MySuperAwesomeScript>());
...
}
?
And is it possible to do something like this:
Destroy(GetComponent<this>())?
Thanks
Tseng
2
Destroy(this);
“this” keyword already refers to the instance of the class itself, so you don’t need any GetComponent calls
Harter
4
Hello again,
Is there any way to find script on the other object like:
public class MySuperAwesomeScript : MonoBehaviour {
...
SomeAnotherGameObject.GetComponent<this>();
...
}
?
Thanks!
GetComponent is expecting a Type, not an instance; so this is the right syntax:
MySuperAwesomeScript otherScript = SomeAnotherGameObject.GetComponent<MySuperAwesomeScript>();
Harter
6
Thanks, but I knew that. I hoped that exist more simple way.
Marrrk
7
How exactly would this look like? The method Jean provided is the simplest you may find. Except you look for something involving extension methods:
someGO.DestroyComponent();
Not really worth the effort.