diff --git a/Assets/Prefabs/Tile.prefab b/Assets/Prefabs/Tile.prefab new file mode 100644 index 0000000..1e58aff Binary files /dev/null and b/Assets/Prefabs/Tile.prefab differ diff --git a/Assets/Prefabs/TileTrap.prefab b/Assets/Prefabs/TileTrap.prefab new file mode 100644 index 0000000..b71fd9e Binary files /dev/null and b/Assets/Prefabs/TileTrap.prefab differ diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs new file mode 100644 index 0000000..1233837 --- /dev/null +++ b/Assets/Scripts/PlayerController.cs @@ -0,0 +1,44 @@ +using UnityEngine; +using System.Collections; + +public class PlayerController : MonoBehaviour { + + public float speed; + GameObject gameController; + + + // Use this for initialization + void Start () { + + gameController = GameObject.Find("GameController"); + } + + // Update is called once per frame + void Update () { + + } + + void FixedUpdate() + { + float moveHorizontal = Input.GetAxis("Horizontal"); + //float moveVertical = Input.GetAxis("Vertical"); + + Vector3 movement = new Vector3(moveHorizontal, 0.0f, 0); + + GetComponent().AddForce(movement * speed * Time.deltaTime); + } + + void OnTriggerEnter(Collider other) + { + if (other.tag == "Tile") + {// && gameController.GetComponent().fallTriggerActivated == true + other.GetComponent().wasTouched = true; + Debug.Log("Tile touched"); + } + if (other.tag == "Trigger") + { + Debug.Log("Trigger entered"); + gameController.GetComponent().fallTriggerActivated = true; + } + } +} diff --git a/Assets/Scripts/TileController.cs b/Assets/Scripts/TileController.cs new file mode 100644 index 0000000..879a7d3 --- /dev/null +++ b/Assets/Scripts/TileController.cs @@ -0,0 +1,58 @@ +using UnityEngine; +using System.Collections; + +public class TileController : MonoBehaviour +{ + + public float speed; + public float speedAddition; + public float seconds; + public bool wasTouched; + public bool timerStart; + float initialTime; + private bool hasStartedMovement; + Vector3 movement; + //GameObject gameController; + + // Use this for initialization + void Start() + { + movement = new Vector3(0.0f, -1, 0.0f); + timerStart = false; + //gameController = GameObject.Find("GameController"); + } + + // Update is called once per frame + void Update() + { + + } + + void FixedUpdate() + { + if (wasTouched == true) + { + CountdownUntilFall(seconds); + } + if (hasStartedMovement == true) + { + GetComponent().isKinematic = false; + GetComponent().AddForce(movement * speed * Time.deltaTime); + speed = speed + speedAddition; + } + } + + private void CountdownUntilFall(float seconds) + { + if (!timerStart) + { + initialTime = Time.realtimeSinceStartup + seconds; + timerStart = true; + } + if (Time.realtimeSinceStartup >= initialTime) + { + hasStartedMovement = true; + } + + } +}