Reputation: 21
So I'm trying to make LeanTween rotate an object to 180/-180 degrees but it makes a stuttery animation while doing so.
Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateScript360 : MonoBehaviour
{
public GameObject level;
public AudioSource audioSource;
public AudioClip rotateSound;
private int rotation;
private bool cooldown;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
IEnumerator cooldownEnd()
{
yield return new WaitForSeconds(1);
cooldown = false;
}
if (cooldown == false)
{
if ((Input.GetKeyDown("x")) || (Input.GetButton("X")))
{
if(rotation != -180)
{
audioSource.PlayOneShot(rotateSound);
rotation = rotation - 90;
LeanTween.rotateX(level, rotation, 1).setEaseOutExpo();
cooldown = true;
StartCoroutine(cooldownEnd());
}
}
if ((Input.GetKeyDown("z")) || (Input.GetButton("Z")))
{
if (rotation != 180)
{
audioSource.PlayOneShot(rotateSound);
rotation = rotation + 90;
LeanTween.rotateX(level, rotation, 1).setEaseOutExpo();
cooldown = true;
StartCoroutine(cooldownEnd());
}
}
}
}
}
What should I do?
Sorry if my English is bad.
I tried to make int rotation
value a little bit lower, cause I was thinking it would make the stutter go away by making LeanTween rotating on 1 side (it would be 178, not 180). But I've gotten the same results.
Upvotes: 2
Views: 53