So my character has 3 sprites in which one of them his shoulder moves slightly to the right of the screen, and my characters arm got an separate sprite, so when the shoulder goes to the right, his arm doesnt goes along (It gets clear in the screenshot). To resolve this, I tried this script:
void Start() {
parentPos = new Vector2(this.transform.localPosition.x,this.transform.localPosition.y);
}
void Update () {
if (this.transform.parent.GetComponent<SpriteRenderer>().sprite.name == "playersprite_cima") {
this.transform.position = parentPos;
}
}
So what Im trying to achieve with this script is to move the arm of my character to the same position of the parent which is the rest of the body, when the specific sprite is active. But i dont think im doing it the right way. Screenshots with the results: