Skip to content

Instantly share code, notes, and snippets.

@lynxelia
Last active February 10, 2018 02:56
Show Gist options
  • Save lynxelia/0551ca14263e367db3099c6a5d2ef769 to your computer and use it in GitHub Desktop.
Save lynxelia/0551ca14263e367db3099c6a5d2ef769 to your computer and use it in GitHub Desktop.
Example of a class that uses OnValidateProperty to set a component field
[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