1
0

Workable character script that should enable the three abilities. 95% correct.

-Dustin
This commit is contained in:
Valtorix5 2016-01-30 14:22:32 -05:00
parent 740be99d5a
commit ffe7055f3f
2 changed files with 152 additions and 14 deletions

View File

@ -3,18 +3,47 @@ using System.Collections;
public class CharacterMovement : MonoBehaviour {
public bool grounded = false;
public bool jump = false;
public bool grounded = true;
public bool foundThing = false;
public bool canPass = false;
public bool changeBox = false;
public bool isStarted = false;
float timeRemainingTransparency = 5;
float timeRemainingTransfer = 5;
float checkTimeRemaining = 5;
public Transform sightStart, sightEnd;
public float secondBoxX, secondBoxY;
public float firstBoxX, firstBoxY;
// Use this for initialization
void Start () {
// Use this for initialization
void Start ()
{
//StartCoroutine(myCoroutine());
}
IEnumerator myCoroutine()
{
//print("wasssssup");
yield return new WaitForSeconds(3f);
//print("now what?");
}
// Update is called once per frame
void Update () {
void Update ()
{
Movement();
powerTransparency();
powerTransfer();
// StartCoroutine(myCoroutine());
// checkTimers();
// print("transfer time: " + timeRemainingTransfer);
// print("check time: " + checkTimeRemaining);
// print("IS starting: " + isStarted);
}
void Movement()
@ -32,13 +61,100 @@ public class CharacterMovement : MonoBehaviour {
transform.eulerAngles = new Vector2(0, 180);
}
/*
if (Input.GetKey(KeyCode.Space))
{
transform.Translate(Vector2.up * Time.deltaTime); //Makes it to where the player can jump up
transform.eulerAngles = new Vector2(90, 0);
}
*/
if (Input.GetKeyDown(KeyCode.T))
powerTeleport();
if (Input.GetKeyDown(KeyCode.F))
{
if (canPass == true)
canPass = false;
else
canPass = true;
}
if (Input.GetKeyDown(KeyCode.G))
{
if (changeBox == true)
changeBox = false;
else
changeBox = true;
}
}
void powerTransfer()
{
//Transfer (enabling the player to "transfer" thier "hit" box behind them)
if (changeBox == true && timeRemainingTransfer >= 0.0 )
{
GetComponent<BoxCollider2D>().offset = new Vector2(secondBoxX, secondBoxY);
timeRemainingTransfer -= Time.deltaTime;
}
else
{
GetComponent<BoxCollider2D>().offset = new Vector2(firstBoxX, firstBoxY);
changeBox = false;
timeRemainingTransfer = 5;
}
}
void powerTransparency()
{
//Transparency (enabling the player to "glitch" through certain boundaries.)
if (canPass == true && timeRemainingTransparency >= 0.0)
{
Physics2D.IgnoreLayerCollision(8, 10, true);
timeRemainingTransparency -= Time.deltaTime;
}
else
{
canPass = false;
Physics2D.IgnoreLayerCollision(8, 10, false);
timeRemainingTransparency = 5;
}
//still need to work on "re increasing" the time remaining variable.
}
void powerTeleport()
{
//Teleportation (enabling teh player to teleport to a location ahead of him.)
Debug.DrawLine(sightStart.position, sightEnd.position, Color.red);
foundThing = Physics2D.Linecast(sightStart.position, sightEnd.position, 1 << LayerMask.NameToLayer("Bounding Wall")); //Pretty much saying if the cast hits a bounding wall, will not enable teleportation
if (foundThing)
transform.position = new Vector2(sightStart.position.x, sightStart.position.y); //Player doesn't move (ish)
else
transform.position = new Vector2(sightEnd.position.x, sightEnd.position.y); //Player moves to the end of the "ray cast"
}
/* void checkTimers()
{
if (timeRemainingTransparency <= 0.0 && checkTimeRemaining >= 0.0 && isStarted == false)
{
isStarted = true;
timeRemainingTransparency += Time.deltaTime;
checkTimeRemaining -= Time.deltaTime;
}
if (timeRemainingTransfer < 0.0 && checkTimeRemaining >= 5 /*&& isStarted == false)
{
isStarted = true;
timeRemainingTransfer += Time.deltaTime;
checkTimeRemaining -= Time.deltaTime;
}
isStarted = false;
}*/
}

View File

@ -4,11 +4,15 @@ using System.Collections;
public class GuardLogic : MonoBehaviour {
public Transform sightStart, sightEnd;
public bool spotted = false;
public bool facingLeft = false;
public GameObject arrow;
// Use this for initialization
void Start ()
{
Update();
InvokeRepeating("Patrol", 0f, Random.Range(2f,6f));
}
@ -21,11 +25,29 @@ public class GuardLogic : MonoBehaviour {
void Raycasting()
{
Debug.DrawLine(sightStart.position, sightEnd.position, Color.green);
spotted = Physics2D.Linecast(sightStart.position, sightEnd.position, 1 << LayerMask.NameToLayer("Player")); //Whatever you're wanting to cast to, should be the 'NameToLayer' option (Third parameter)
}
void Behaviours()
{
if (spotted == true)
arrow.SetActive(true);
else
arrow.SetActive(false);
}
void Patrol()
{
facingLeft = !facingLeft;
if (facingLeft == true)
transform.eulerAngles = new Vector2(0, 0);
else
transform.eulerAngles = new Vector2(0, 180);
}
}