How do I return the rotation of another game object?

Hi.

I’ve been struggling with rotation value checking for few hours now.
I’m trying to read my cameras Y rotation so I can use different controls when my camera is being used from a different angle.

My code for the “movement” - changing gravity, is here:

using UnityEngine;
using System.Collections;

public class Gravity : MonoBehaviour
{

    public GameObject MCAM = GameObject.Find("::cameraController");


    public Vector3[] gravityList = new Vector3[] { };
    public Vector3[] gravityList2 = new Vector3[] { };
    public Vector3[] gravityList3 = new Vector3[] { };
    public Vector3[] gravityList4 = new Vector3[] { };

    /**
    void Start()
    {
        GameObject MainCam = GameObject.Find("::cameraController");
        CameraRotation cRot = MainCam.GetComponent<CameraRotation>();
    } **/

    public void FixedUpdate() {
        /**
        yRotation += Input.GetAxis("Horizontal");
        transform.eulerAngles = new Vector3(0, yRotation, 0);
        **/

        if (MCAM.transform.localRotation.y == 0)
        {
            if (gravityList.Length < 5)
            {

                Debug.Log("gravity List has to be more or exactly at 5");
                return;

            }

            if (Input.GetKeyDown(KeyCode.Space))
            {
                //Restore
                Physics.gravity = gravityList[0];
                // Handheld.Vibrate();
            }


            if (swipeManager.Instance.IsSwiping(SwipeDirection.Up))
            {
                Physics.gravity = gravityList[1];
                Debug.Log("Gravity IS Up");
                //  Handheld.Vibrate();
            }

            if (swipeManager.Instance.IsSwiping(SwipeDirection.Left))
            {
                Physics.gravity = gravityList[2];
                Debug.Log("Gravity IS Left");
                //   Handheld.Vibrate();
            }

            if (swipeManager.Instance.IsSwiping(SwipeDirection.Down))
            {
                Physics.gravity = gravityList[3];
                Debug.Log("Gravity IS Down");
                //  Handheld.Vibrate();
            }

            if (swipeManager.Instance.IsSwiping(SwipeDirection.Right))
            {
                Physics.gravity = gravityList[4];
                Debug.Log("Gravity IS Right");
                //   Handheld.Vibrate();
            }
        }

            else if (MCAM.transform.localRotation.y == 90.00001 || MCAM.transform.localRotation.y == 90)
            {
                Debug.Log("ANGLE IS 90");
                if (gravityList2.Length < 5)
                {

                    Debug.Log("gravity List BONUS has to be more or exactly at 5");
                    return;

                }

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    //Restore
                    Physics.gravity = gravityList2[0];
                    // Handheld.Vibrate();
                }


                if (swipeManager.Instance.IsSwiping(SwipeDirection.Up))
                {
                    Physics.gravity = gravityList2[1];
                    Debug.Log("Gravity IS Up");
                    //  Handheld.Vibrate();
                }

                if (swipeManager.Instance.IsSwiping(SwipeDirection.Left))
                {
                    Physics.gravity = gravityList2[2];
                    Debug.Log("Gravity IS Left");
                    //   Handheld.Vibrate();
                }

                if (swipeManager.Instance.IsSwiping(SwipeDirection.Down))
                {
                    Physics.gravity = gravityList2[3];
                    Debug.Log("Gravity IS Down");
                    //  Handheld.Vibrate();
                }

                if (swipeManager.Instance.IsSwiping(SwipeDirection.Right))
                {
                    Physics.gravity = gravityList2[4];
                    Debug.Log("Gravity IS Right");
                    //   Handheld.Vibrate();
                }
            }
            // UUSI ALKAA NYT

            else if (MCAM.transform.localRotation.y == 180)
            {
                Debug.Log("ANGLE IS 180");
                if (gravityList3.Length < 5)
                {

                    Debug.Log("gravity List BONUS has to be more or exactly at 5");
                    return;

                }

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    //Restore
                    Physics.gravity = gravityList3[0];
                    // Handheld.Vibrate();
                }


                if (swipeManager.Instance.IsSwiping(SwipeDirection.Up))
                {
                    Physics.gravity = gravityList3[1];
                    Debug.Log("Gravity IS Up");
                    //  Handheld.Vibrate();
                }

                if (swipeManager.Instance.IsSwiping(SwipeDirection.Left))
                {
                    Physics.gravity = gravityList3[2];
                    Debug.Log("Gravity IS Left");
                    //   Handheld.Vibrate();
                }

                if (swipeManager.Instance.IsSwiping(SwipeDirection.Down))
                {
                    Physics.gravity = gravityList3[3];
                    Debug.Log("Gravity IS Down");
                    //  Handheld.Vibrate();
                }

                if (swipeManager.Instance.IsSwiping(SwipeDirection.Right))
                {
                    Physics.gravity = gravityList3[4];
                    Debug.Log("Gravity IS Right");
                    //   Handheld.Vibrate();
                }
            }


                    else if (MCAM.transform.localRotation.y == -90.00001 || MCAM.transform.localRotation.y == -90)
                    {
                        Debug.Log("ANGLE IS -90");
                        if (gravityList4.Length < 5)
                        {

                            Debug.Log("gravity List BONUS has to be more or exactly at 5");
                            return;

                        }

                        if (Input.GetKeyDown(KeyCode.Space))
                        {
                            //Restore
                            Physics.gravity = gravityList4[0];
                            // Handheld.Vibrate();
                        }


                        if (swipeManager.Instance.IsSwiping(SwipeDirection.Up))
                        {
                            Physics.gravity = gravityList4[1];
                            Debug.Log("Gravity IS Up");
                            //  Handheld.Vibrate();
                        }

                        if (swipeManager.Instance.IsSwiping(SwipeDirection.Left))
                        {
                            Physics.gravity = gravityList4[2];
                            Debug.Log("Gravity IS Left");
                            //   Handheld.Vibrate();
                        }

                        if (swipeManager.Instance.IsSwiping(SwipeDirection.Down))
                        {
                            Physics.gravity = gravityList4[3];
                            Debug.Log("Gravity IS Down");
                            //  Handheld.Vibrate();
                        }

                        if (swipeManager.Instance.IsSwiping(SwipeDirection.Right))
                        {
                            Physics.gravity = gravityList4[4];
                            Debug.Log("Gravity IS Right");
                            //   Handheld.Vibrate();
                        }
                    }
                }
            }
// }

I have no idea what I’m doing right or wrong with the rotation checking.
Please help.

Thanks.

Well, unless you intended to do Quaternion math, then every one of your:

MCAM.transform.localRotation.y

references should be:

MCAM.transform.localRotation.eulerAngles.y