Hi, I have been working on a little 2d platformer for a while now and am having some issues with an idea I had. I am trying to change the player game object as a transformation not in the unity sense lol. The two different objects share a control script, and I am faking a parent with the Parent Constraint component to keep them together while switching the renderer, colliders, and animator off. I am using the new Player Input component and can see the bool changing when I run it but the other components do not change just the serialized field _change. My C# and unity knowledge level is armature at best but we all have to start somewhere. If anyone has any ideas on how to get this working I would appreciate the input!
This is the section of the control script I want to handle the change.
[SerializeField]
private bool _change = false;
public bool Change
{
get
{
return _change;
}
set
{
if (_change == true)
{
avatar2.GetComponent<ParentConstraint>().enabled = false;
avatar2.GetComponent<SpriteRenderer>().enabled = true;
avatar2.GetComponent<CapsuleCollider2D>().enabled = true;
avatar2.GetComponent<Animator>().enabled = true;
avatar1.GetComponent<ParentConstraint>().enabled = true;
avatar1.GetComponent<SpriteRenderer>().enabled = false;
avatar1.GetComponent<CapsuleCollider2D>().enabled = false;
avatar1.GetComponent<Animator>().enabled = false;
}
else
{
avatar1.GetComponent<ParentConstraint>().enabled = false;
avatar1.GetComponent<SpriteRenderer>().enabled = true;
avatar1.GetComponent<CapsuleCollider2D>().enabled = true;
avatar1.GetComponent<Animator>().enabled = true;
avatar2.GetComponent<ParentConstraint>().enabled = true;
avatar2.GetComponent<SpriteRenderer>().enabled = false;
avatar2.GetComponent<CapsuleCollider2D>().enabled = false;
avatar2.GetComponent<Animator>().enabled = false;
}
Change = _change;
}
}
public void change(InputAction.CallbackContext context)
{
if (context.started)
{
_change = !_change;
}
}
}