Search Unity

How to add a 3rd rotation to this

Discussion in 'Scripting' started by Treasureman, Feb 10, 2016.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    I have a script that can make a UI Image rotate at 90 and -90 degrees along with the Horizontal Axis. I want to make it also rotate to 0 and 180 on the same axis on the Vertical Axis so that it can rotate 360. Here's the script...
    Code (CSharp):
    1.     using UnityEngine;
    2.     using UnityEngine.UI;
    3.     using System.Collections;
    4.  
    5.     public class MenuArrowH : MonoBehaviour
    6.     {
    7.         public float normalAngle = 180;
    8.         public float leanAngle = 90;
    9.         public float smooth = 100;
    10.         public Image imageToLerp;
    11.  
    12.         // Use this for initialization
    13.         void Start()
    14.         {
    15.  
    16.         }
    17.  
    18.         // Update is called once per frame
    19.         void Update()
    20.         {
    21.             Vector3 euler = imageToLerp.transform.eulerAngles;
    22.             float hInput = Input.GetAxis("Horizontal");
    23.  
    24.             if (hInput < 0)
    25.             {
    26.                 euler.z = Mathf.LerpAngle(euler.z, leanAngle, Time.deltaTime * smooth);
    27.             }
    28.             else if (hInput > 0)
    29.             {
    30.                 euler.z = Mathf.LerpAngle(euler.z, -leanAngle, Time.deltaTime * smooth);
    31.             }
    32.             else
    33.             {
    34.                 euler.z = Mathf.LerpAngle(euler.z, normalAngle, Time.deltaTime * smooth);
    35.             }
    36.  
    37.             imageToLerp.transform.eulerAngles = euler;
    38.         }
    39.     }
    How could I do this? I've tried with a lot of issues. What can I do?