Home > front end >  Why does setting my Rotate.z change all variables?
Why does setting my Rotate.z change all variables?

Time:07-12

Im trying to make a sprite rotate onscreen to show the player how their Jet is rotated while they fly.

Here is my code

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

public class AircraftScript : MonoBehaviour
{
public float Altitude;
public Text AltitudeText;

public GameObject AircraftImage;

public GameObject Aircraft;

void Update()
{
   Altitude = Aircraft.GetComponent<Rigidbody>().position.y;
   AltitudeText.text = Altitude   "ft";
   
   AircraftImage.Rotate.z = Aircraft.Rotate.z;
}

}

It changed all the values of the Sprite (x,y,z) instead of just the z.

I did also try AircraftImage.Rotate = new Vector3(0 , 0 , Aircraft.Rotate); and AircraftImage.Rotate = new Vector3(0 , 0 , Aircraft.Rotate.z);

neither worked, what have I done wrong?

CodePudding user response:

I don't understand your code: Aircraft and AircraftImage are GameObjects, and GameObjects don't have the Rotate method, so that code should throw an exception. Anyway I try to help you anyway. Try using this code:

AircraftImage.GetComponent<RectTransform>().eulerAngles = new Vector3(0, 0, Aircraft.transform.eulerAngles.z);
  • Related