using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hit : MonoBehaviour {
public float rotSpeed = 10f;
public float rotBack = -10f;
public Vector3 startPoint;
public Animator anim;
public float Timer = 0f;
public float waitTime = 1f;
public bool Timeron;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if(Timeron == true)
{
Timer -= Time.deltaTime;
}
if (Input.GetKey("w"))
{
transform.Rotate(0, 0, rotBack);
Timeron = true;
}
if (Timer < waitTime)
{
transform.Rotate(0, 0, rotSpeed);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hit : MonoBehaviour
{
[Range(0,1000)]
public float forwardRotationSpeed = 10f;
[Range(0,1000)]
public float backwardRotationSpeed = 10f;
[Range(0,3600)]
public float waitDuration = 1f;
public Vector3 startPoint;
private Animator anim;
private float waitTimer = 0f;
private bool rotated;
private float rotation;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if ( Input.GetKey( "w" ) )
{
rotation += forwardRotationSpeed * Time.deltaTime;
transform.Rotate( 0, 0, forwardRotationSpeed * Time.deltaTime );
rotated = true;
waitTimer = 0;
}
else if ( rotated )
{
waitTimer += Time.deltaTime;
if ( waitTimer > waitDuration && rotation > 0 )
{
float r = Mathf.Min( backwardRotationSpeed * Time.deltaTime, rotation );
rotation -= r;
transform.Rotate( 0, 0, -r );
}
}
}
}
void Awake() { StartCoroutine(Test()); }
IEnumerator Test()
{
Vector3 startVector = new Vector3(0,0,0);
Vector3 endVector = new Vector3(0, 180, 0);
while (transform.rotation.eulerAngles != endVector)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(endVector), 0.5f);
yield return null;
}
yield return new WaitForSeconds(1);
while (transform.rotation.eulerAngles != startVector)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(startVector), 1);
yield return null;
}
}