Added obstacles that move and implemented them into the game modes

This commit is contained in:
Gregory Campbell
2020-02-05 21:54:39 -05:00
parent 0339e62484
commit fc24e21135
22 changed files with 5282 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovingBlock : MonoBehaviour
{
public bool xaxis;
public bool zaxis;
public float speed;
public GameObject block;
bool moveXpos;
bool moveZpos;
Vector3 startPos;
void Start()
{
startPos = block.transform.position;
if(Random.Range(0,2) == 0)
{
xaxis = true;
} else {
xaxis = false;
}
if(Random.Range(0,2) == 0)
{
zaxis = true;
} else {
zaxis = false;
}
if(Random.Range(0,2) == 0)
{
moveXpos = true;
} else {
moveXpos = false;
}
if(Random.Range(0,2) == 0)
{
moveZpos = true;
} else {
moveZpos = false;
}
}
// Update is called once per frame
void Update()
{
if(xaxis)
{
if(block.transform.position.x > startPos.x+15)
{
moveXpos = false;
}
if(block.transform.position.x < startPos.x-15)
{
moveXpos = true;
}
if(moveXpos) transform.position += Vector3.right * Time.deltaTime * speed;
if(!moveXpos) transform.position += Vector3.left * Time.deltaTime * speed;
}
if(zaxis)
{
if(block.transform.position.z > startPos.z+15)
{
moveZpos = false;
}
if(block.transform.position.z < startPos.z-15)
{
moveZpos = true;
}
if(moveZpos) transform.position += Vector3.forward * Time.deltaTime * speed;
if(!moveZpos) transform.position += Vector3.back * Time.deltaTime * speed;
}
}
}