2017-09-04 11:33:52 -05:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
2017-09-05 15:51:57 -05:00
|
|
|
|
using UnityEngine.SceneManagement;
|
2017-09-05 20:11:49 -05:00
|
|
|
|
using UnityEngine.UI;
|
2017-09-04 11:33:52 -05:00
|
|
|
|
|
|
|
|
|
// Simple script for a test I need to do
|
|
|
|
|
|
|
|
|
|
public class PlayerController : MonoBehaviour {
|
|
|
|
|
|
|
|
|
|
public float jumpPower;
|
2017-09-05 19:44:20 -05:00
|
|
|
|
public GameObject rocketPrefab;
|
2017-09-07 10:18:05 -05:00
|
|
|
|
private float reloadTime = 0.25f;
|
2017-09-07 00:50:49 -05:00
|
|
|
|
private bool reloading = false;
|
2017-09-07 14:21:58 -05:00
|
|
|
|
private static PlayerController controller;
|
|
|
|
|
private bool alive = true;
|
2017-09-04 11:33:52 -05:00
|
|
|
|
|
2017-09-07 14:21:58 -05:00
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
if (controller)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("More than one player controller in the scene! Deleting this controller.");
|
|
|
|
|
Destroy(this);
|
|
|
|
|
}
|
|
|
|
|
controller = this;
|
|
|
|
|
alive = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PlayerController GetController()
|
|
|
|
|
{
|
|
|
|
|
if (!controller)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("No player controller currently in the scene.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return controller;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void KillPlayer()
|
|
|
|
|
{
|
|
|
|
|
alive = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RevivePlayer()
|
|
|
|
|
{
|
|
|
|
|
alive = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update () {
|
|
|
|
|
if (!alive)
|
|
|
|
|
return;
|
2017-09-07 00:50:49 -05:00
|
|
|
|
/*// Basic jumping
|
2017-09-04 11:33:52 -05:00
|
|
|
|
if (Input.GetKeyDown (KeyCode.Space)) {
|
|
|
|
|
GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, jumpPower);
|
2017-09-07 00:50:49 -05:00
|
|
|
|
}*/
|
2017-09-04 16:39:17 -05:00
|
|
|
|
|
2017-09-07 00:50:49 -05:00
|
|
|
|
if (Input.GetMouseButtonDown(0) && !reloading)
|
2017-09-04 16:39:17 -05:00
|
|
|
|
{
|
2017-09-07 00:50:49 -05:00
|
|
|
|
reloading = true;
|
|
|
|
|
StartCoroutine("Reload");
|
2017-09-05 19:44:20 -05:00
|
|
|
|
Vector2 rocketPos = transform.position;
|
|
|
|
|
GameObject rocket = Instantiate(rocketPrefab, rocketPos, Quaternion.identity);
|
|
|
|
|
rocket.GetComponent<RocketController>().player = this;
|
2017-09-07 00:50:49 -05:00
|
|
|
|
Physics2D.IgnoreCollision(rocket.GetComponent<Collider2D>(), GetComponent<Collider2D>());
|
2017-09-05 19:44:20 -05:00
|
|
|
|
}
|
2017-09-04 11:33:52 -05:00
|
|
|
|
}
|
2017-09-05 20:11:49 -05:00
|
|
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D other)
|
|
|
|
|
{
|
|
|
|
|
//Check the provided Collider2D parameter other to see if it is tagged "PickUp", if it is...
|
|
|
|
|
if (other.gameObject.CompareTag ("Finish Line")) {
|
2017-09-07 00:50:49 -05:00
|
|
|
|
LevelController.GetController().WinLevel();
|
|
|
|
|
}
|
2017-09-05 20:38:10 -05:00
|
|
|
|
|
|
|
|
|
// Deathbox and saws restart level
|
|
|
|
|
if (other.gameObject.CompareTag ("Deathbox")) {
|
2017-09-07 00:50:49 -05:00
|
|
|
|
LevelController.GetController().ResetLevel();
|
2017-09-05 15:51:57 -05:00
|
|
|
|
}
|
2017-09-05 20:11:49 -05:00
|
|
|
|
}
|
2017-09-07 00:50:49 -05:00
|
|
|
|
|
|
|
|
|
private IEnumerator Reload()
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSeconds(reloadTime);
|
|
|
|
|
reloading = false;
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
2017-09-04 11:33:52 -05:00
|
|
|
|
}
|