Search Unity

How can I extend the parameters to add also direction of the rotation ?

Discussion in 'Scripting' started by Chocolade, Jan 11, 2019.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    933
    Code (csharp):
    1.  
    2. private void RotateDegrees(Vector3 degrees,
    3.         params Animator[] anims)
    4.     {
    5.         Quaternion quaternion = Quaternion.Euler(degrees);
    6.         foreach (var anim in anims)
    7.         {
    8.             anim.transform.rotation = Quaternion.Slerp(anim.transform.rotation, quaternion, rotationSpeed * Time.deltaTime);
    9.         }
    10.     }
    11.  
    For example using this method:

    Code (csharp):
    1.  
    2. RotateDegrees(new Vector3(0, 0, 0), animators[0], animators[1]);
    3.  
    But if I want to make that animators[0] will start rotating from right to left and animators[1] from left to right ?
    And do it in one line like I'm doing now but with a simple way to decide to what side it will rotate each object.