ajout scripts et prefabs pour tuiles

This commit is contained in:
karakune 2016-06-25 15:53:55 -04:00
parent 999055b8f8
commit 0259352313
4 changed files with 102 additions and 0 deletions

BIN
Assets/Prefabs/Tile.prefab Normal file

Binary file not shown.

Binary file not shown.

View File

@ -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<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Tile")
{// && gameController.GetComponent<GameController>().fallTriggerActivated == true
other.GetComponent<TileController>().wasTouched = true;
Debug.Log("Tile touched");
}
if (other.tag == "Trigger")
{
Debug.Log("Trigger entered");
gameController.GetComponent<GameController>().fallTriggerActivated = true;
}
}
}

View File

@ -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<Rigidbody>().isKinematic = false;
GetComponent<Rigidbody>().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;
}
}
}