Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

68 lines
1.8 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveBlock : MonoBehaviour
{
public float moveYAmount = 20.0f;
public float moveSpeed = 1.0f;
public float waitTime = 5.0f;
public float rotateSpeed = 10.0f;
private float startY;
private bool goingUp = true;
private float stoppedUntilTime;
private float moveUpAmount;
protected virtual void Start ()
{
startY = transform.position.y;
moveUpAmount = Mathf.Abs(moveYAmount);
if(moveYAmount < 0.0f)
{
startY -= moveYAmount;
goingUp = false;
}
stoppedUntilTime = Time.time + waitTime;
}
protected virtual void Update ()
{
if( Time.time > stoppedUntilTime)
{
if(goingUp)
{
if(transform.position.y < startY+moveUpAmount)
{
Vector3 newPosition = transform.position;
newPosition.y += Time.deltaTime * moveSpeed;
transform.position = newPosition;
}
else
{
goingUp = false;
stoppedUntilTime = Time.time + waitTime;
}
}
else
{
if(transform.position.y > startY)
{
Vector3 newPosition = transform.position;
newPosition.y -= Time.deltaTime * moveSpeed;
transform.position = newPosition;
}
else
{
goingUp = true;
stoppedUntilTime = Time.time + waitTime;
}
}
}
transform.Rotate(new Vector3(0.0f, rotateSpeed * Time.deltaTime, 0.0f));
}
}