Rotate an object

I have a central object which is rotating around itself. I also got an arrow which is following the central rotation. If I click on the screen the rotation changes to the opposite direction.

I want the arrow object to flip around so it would point to the rotation direction. How can I do this?

My script so far:

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

public class CenterRotation : MonoBehaviour
{
    public int direction= 1;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.Rotate(new Vector3(0, 0, direction), Space.Self);
    
        if (Input.GetMouseButtonDown(0))
        {
            {
                if (direction> 0)
                {
                    direction= -1;
                    Debug.Log("Changes direction!");
                }
                else
                {
                    direction= 1;
                    Debug.Log("Normal rotation!");
                }
            }
        }
    }
}

I attached pictures to the question just to be clear.

Thanks!

5828896--618031--help.PNG

Can you set “flipY” or “flipX” on the SpriteRenderer for the arrow at the same time you change rotate direction?

1 Like

Thanks for your answer. I could solved it be flipX.

Code:

public class SpriteFlipper : MonoBehaviour
{
   // variable to hold a reference to our SpriteRenderer component
   private SpriteRenderer mySpriteRenderer;
   // This function is called just one time by Unity the moment the component loads
   private void Awake()
   {
        // get a reference to the SpriteRenderer component on this gameObject
        mySpriteRenderer = GetComponent<SpriteRenderer>();
   }
   // This function is called by Unity every frame the component is enabled
   private void Update()
   {     
        // if the A key was pressed this frame
        if(Input.GetKeyDown(KeyCode.A))
        {
            // if the variable isn't empty (we have a reference to our SpriteRenderer
            if(mySpriteRenderer != null)
            {
                 // flip the sprite
                 mySpriteRenderer.flipX = true;
            }
        }
    }
}