Last active
February 10, 2018 02:56
-
-
Save lynxelia/0551ca14263e367db3099c6a5d2ef769 to your computer and use it in GitHub Desktop.
Example of a class that uses OnValidateProperty to set a component field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[RequireComponent(typeof(Rigidbody2D))] | |
public class MyCustomClass : BaseMonoBehaviour | |
{ | |
public bool m_CanMove; | |
public override bool OnValidateProperty(string propertyName) | |
{ | |
if (propertyName == "m_CanMove") | |
{ | |
if (!m_CanMove) | |
{ | |
GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static; | |
return true; | |
} | |
} | |
return base.OnValidateProperty(propertyName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment