Platform movement and elimination zones

Adds scripts for moving any object up/down, left/right or  forwards/backwars and eliminating the player.
This commit is contained in:
Jan Groß
2018-09-01 20:49:43 +02:00
parent c073f272f6
commit f511f2bbbf
7 changed files with 1514 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a972842cd67bc904a93eac69a3331151
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,92 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour {
[System.Serializable]
class MovementDirection
{
[SerializeField]
private bool enabled = false;
[SerializeField]
private enum Direction { Left_Right, Up_Down, Fwd_Bkw }
[SerializeField]
private Direction direction;
[SerializeField]
private bool loop = false;
[SerializeField]
private bool goBack = false;
[SerializeField]
private float distance = 100;
[SerializeField]
private float speed = 0;
[SerializeField]
private float dist;
private Vector3 initialPosition;
public void SetInitialPosition(Vector3 initPos)
{
initialPosition = initPos;
}
public Vector3 Move(Vector3 dirIn)
{
int dir = (int)direction;
Vector3 dirOut = dirIn;
enabled = loop ? true : enabled;
if (enabled)
{
dist = initialPosition[dir] - dirOut[dir];
if (goBack)
{
dirOut[dir] += speed * Time.deltaTime;
}
else
{
dirOut[dir] -= speed * Time.deltaTime;
}
if (dist > distance && !goBack)
{
if (loop)
{
goBack = true;
}
else
{
enabled = false;
}
}
else if (dist <= 0)
{
goBack = false;
}
}
return dirOut;
}
}
[SerializeField]
private List<MovementDirection> directions;
// Use this for initialization
void Start () {
foreach (MovementDirection direction in directions)
{
direction.SetInitialPosition(transform.position);
}
}
// Update is called once per frame
void Update () {
foreach ( MovementDirection direction in directions)
{
transform.position = direction.Move(transform.position);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ff6f74910bdc270439212f0b80ab09b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EliminatePlayer : MonoBehaviour {
[SerializeField]
private string name = "Generic trap";
[SerializeField]
private float resapwnDelay = 0;
[Tooltip("Optional particle effect. Spawned when player enters the trigger")]
[SerializeField]
private GameObject effect;
[SerializeField]
private LurchRespawn player;
[SerializeField]
private bool killQueued = false;
[SerializeField]
private float rdCounter = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (rdCounter <= 0 && killQueued)
{
player.RespawnLurch(name);
killQueued = false;
} else
{
rdCounter -= Time.deltaTime;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.transform.root.tag == "Player")
{
rdCounter = resapwnDelay;
killQueued = true;
if(effect != null)
{
GameObject.Instantiate(effect);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 558ac06dec86b64459dd109124ea89be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: