Inheriting a GameObjects Rotation:

I am trying to copy the rotation of a GameObject to use it to display on the HUD/Interface as a GUI Texture.

Here is what I have, but it is throwing errors. I seen a similar post, but I can not find it.

/
/
/
 public GameObject target;
    public bool inheritParentRotation = true;
	public int Speed = 1;

    void Start()
    {
        target=Transform.GetComponent<GameObject>();
    }

    void Update ()
    {
        if(inheritParentRotation)
		{
			target.rotation = Vector3.zero * Speed;
		}
        else
		{
            target.rotation = Vector3.zero;
		}
    }
/
/
/

Transform.rotation is a Quaternion not a Vector3. Use Transform.eulerAngles or Transform.Rotate() instead.

Tried it, I think I am going about this the wrong way, or I am just competely wrong…

GameObjects don’t have a rotation, Transforms do. You either need to use target.transform.rotation, or declare target as a Transform instead of a GameObject.

Am I on the right track??

/
/
/
public GameObject target;

	public bool inheritParentRotation = true;

  

    void Start()

    {

        target=transform.rotation.GetComponent<GameObject>();

    }



    void Update ()

    {

        if(inheritParentRotation)

        {

            target.rotation = Transform.Rotate();

        }

        else

        {

            target.rotation = Transform.Rotate();

        }



    }
/
/
/

This should fix your compile errors.

/
/
/
 public GameObject target;
    public bool inheritParentRotation = true;
	public int Speed = 1;

    void Start()
    {
        target = transform.GetComponent<GameObject>();
    }

    void Update ()
    {
        if(inheritParentRotation)
		{
			target.transform.rotation = Quaternion.identity * Speed;
		}
        else
		{
            target.transform.rotation = Quaternion.identity;
		}
    }
/
/
/

Even with your description, I’m not exactly sure what you’re trying to achieve though, so I don’t know if this is the behavior you desire or not.

I’ll test it soon and let you know.

Thanks

I get these errors still…

Operator *' cannot be applied to operands of type UnityEngine.Quaternion’ and `int’

An object reference is required to access non-static member `UnityEngine.Component.GetComponent(System.Type)’

Because you can’t multiply a Quaternion by an int. Also why are you doing transform.GetComponent() instead of just transform.gameObject? You’re also taking a transform and assigned its GameObject to a variable only to traverse back down that variable to the transform again. Why not just make target a Transform and leave it at that?

As with the others - I’m not sure what you’re trying to achieve here so its difficult to advise beyond that.

My open explains what I an try to achieve. I have a GUI texture on a camera and I want to transfer the rotation of the gameobject it represents to it.

You can’t rotate a GUI Texture.

Not without using a sprite sheet or something similar.

Zahel is correct. Best bet would be to make a quad mesh and map your texture to it. At that point you can rotate however you wish.

Seems like this should be able to happen. Is a texture going to have a nice HUD like look to it like the GUI does is my concern.

What I did was use another camera and create a 2 plane mesh with my objects representation texture on them and put the camera in orthoand lined it up where I want it, but now I have the camera in every camera view. How do I disable the camera from other camera views??

Just turn the Camera off when you don’t want it.

Yeah, I figured it out, I just incorporated it into my multiple cam script. Works perfectly.

Thanks guys.