Flipping MeshRenderer upon direction change

Hello,

I have a 3D mesh Renderer that I’m trying to move from A to B. Currently the movement is fine and works well. However what im trying to do right now is flip the rotation in Y. So its a spike, moves from A to B, then id like it to flip when its going from B to A

Adding this GIF of what it does, Hopefully you can see the spike coming down needs to have flipped, it could be a Scale to-1, but please advise.

Here is my code for everything other than the flipping. It is also a 2.5 D game with 3D models.

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

public class ShootingSpike : MonoBehaviour
{

    public float moveSpeed = 5f;
    public Transform pointA, pointB;

    private bool movingUp;

    private Rigidbody2D theRB;

// A Public variable to add my 3D model. 
    public MeshRenderer myModel;



    // Start is called before the first frame update
    void Start()
    {
        theRB = GetComponent<Rigidbody2D>();
        pointA.parent = null;
        pointB.parent = null;

        movingUp = true;

    }

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

            theRB.velocity = new Vector2(theRB.velocity.x, moveSpeed);


            if (transform.position.y > pointA.position.y)
            {
                movingUp = false;
            }
        } else
        {
            theRB.velocity = new Vector2(theRB.velocity.x, -moveSpeed);
            if (transform.position.y < pointB.position.y)
            {
                movingUp = true;
            }
        }
    }
}

maybe this?

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ShootingSpike : MonoBehaviour
 {
 
     public float moveSpeed = 5f;
     public Transform pointA, pointB;
     Vector3 baseRotation;
 
     private bool movingUp;
 
     private Rigidbody2D theRB;
     // A Public variable to add my 3D model. 
     public MeshRenderer myModel;
 
 
 
     // Start is called before the first frame update
     void Start()
     {
         theRB = GetComponent<Rigidbody2D>();
         baseRotation = transform.rotation;
         
         pointA.parent = null;
         pointB.parent = null;
 
         movingUp = true;
 
     }
 
     // Update is called once per frame
     void Update()
     {
       if (movingUp)
      {
        MoveUp();
      } 
      else
      {
        FallDown();
      }
     }

     void FallDown()
     {
       theRB.velocity = new Vector2(theRB.velocity.x, -moveSpeed);
       transform.eulerAngles.z = -baseRotation.z;
       
       if (transform.position.y < pointB.position.y)
       {
         movingUp = true;
       }
     }

     void MoveUp()
     {   
       theRB.velocity = new Vector2(theRB.velocity.x, moveSpeed);
       transform.eulerAngles.z = -baseRotation.z;
     
       if (transform.position.y > pointA.position.y)
       {
         movingUp = false;
       }
     }
 }

just rotating the spike on the z axis should do the trick i think

@rage_co

Thanks again,

the rotate Z should work. I have three errors as i mentioned above, thanks for your input.

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

public class ShootingSpike : MonoBehaviour
{


    [Header("Controller")]
    public float moveSpeed = 5f;




    [Header("Targets")]
    public Transform pointA;
    public Transform pointB;

    private Vector3 baseRotation;

    private bool movingUp;

    private Rigidbody2D theRB;




    // Start is called before the first frame update
    void Start()
    {
        theRB = GetComponent<Rigidbody2D>();
        baseRotation = transform.rotation;

        pointA.parent = null;
        pointB.parent = null;

        movingUp = true;

    }

    // Update is called once per frame
    void Update()
    {
        if (movingUp)
        {
            MoveUp();
        }
        else
        {
            FallDown();
        }
    }

    void FallDown()
    {
        theRB.velocity = new Vector2(theRB.velocity.x, -moveSpeed);
        transform.eulerAngles.z = -baseRotation.z;

        if (transform.position.y < pointB.position.y)
        {
            movingUp = true;
        }
    }

    void MoveUp()
    {
        theRB.velocity = new Vector2(theRB.velocity.x, moveSpeed);
        transform.eulerAngles.z = -baseRotation.z;

        if (transform.position.y > pointA.position.y)
        {
            movingUp = false;
        }
    }
}