Flipping a card 180 but instead of flipping from the middle the code flips it from the side ,I want to flip my card 180 but it flips it from the side instead of the middle of the sprite

I am using this code from a video on YT and when he does it it works 100% but when i do it my card instead of rotating 190 from the middle of the card it flips it on the right edge.

=

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Flip : MonoBehaviour {

public int fps = 60;
public float rotateDegreePerSecond = 180f;
public bool isFaceUp = false;

const float FLIP_LIMIT_DEGREE = 180f;

float waitTime;
    bool isAnimationProcessing = false;

// Use this for initialization
void Start() {
    waitTime = 1.0f / fps;

}

// Update is called once per frame
void Update() {

}

void OnMouseDown() {

    if (isAnimationProcessing)
    {
        return;

    }
    StartCoroutine(flip());
}

IEnumerator flip ()
{
    isAnimationProcessing = true;

    bool done = false;
    while (!done)
    {
        float degree = rotateDegreePerSecond * Time.deltaTime;
        if (isFaceUp)
        {
            degree = -degree;
        }

        transform.Rotate(new Vector3(0, degree, 0));
        if(FLIP_LIMIT_DEGREE < transform.eulerAngles.y)
        {
            transform.Rotate(new Vector3(0, -degree, 0));
            done = true;
        }

        yield return new WaitForSeconds(waitTime);
    }
    isFaceUp = !isFaceUp;
    isAnimationProcessing = false;
}

}

,

It is likely that the origin of your model is not at the center, which is resulting in your weird flipping issue. You can either fix the model or you can create a “container” GameObject that’s offset from the child card. and then flip that. The latter is a hack… the former is the correct solution but I don’t know how familiar you are with modelling to fix the origin.