Created
August 15, 2019 16:41
-
-
Save smkplus/3d27e64415a07684c734515df8811c32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class SineMovement : MonoBehaviour | |
{ | |
public float MoveSpeed = 5.0f; | |
public float frequency = 20.0f; | |
public float magnitude = 0.5f; | |
private Vector3 axis; | |
private Vector3 pos; | |
void Start() | |
{ | |
pos = transform.position; | |
axis = transform.up; | |
StartCoroutine(Delay()); | |
// Time.timeScale = 3; | |
} | |
bool landed = false; | |
public float timer; | |
IEnumerator Delay() | |
{ | |
while (true) | |
{ | |
if (!landed) | |
timer += .01f; | |
pos += transform.forward * Time.deltaTime * MoveSpeed; | |
float number = Mathf.Abs(Mathf.Sin(timer * frequency)) * magnitude; | |
transform.position = pos + axis * number; | |
// Debug.Log(number / magnitude); | |
if (number <= .1f && !landed) | |
{ | |
Debug.Log("Test"); | |
yield return new WaitForSeconds(1); | |
landed = true; | |
} | |
landed = false; | |
yield return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment