Skip to content

Commit

Permalink
Door/Key Push
Browse files Browse the repository at this point in the history
Door, Key Works
OVerworld in progress
  • Loading branch information
aps16104 committed Apr 14, 2020
1 parent 1dce490 commit 1fdc606
Show file tree
Hide file tree
Showing 1,121 changed files with 526 additions and 26 deletions.
17 changes: 17 additions & 0 deletions Platformer/Assets/Scripts/Door.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Door : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
SceneManager.LoadScene("Overworld");
}
}

}
11 changes: 11 additions & 0 deletions Platformer/Assets/Scripts/Door.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 30 additions & 22 deletions Platformer/Assets/Scripts/Player_Controller.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class Player_Controller : MonoBehaviour
{
public float speed = 7.5f;
public Rigidbody2D rb;
public float speed = 7.5f; //speed
public Rigidbody2D rb; //Rigidbody

int jumps; //Amount of jumps available
int maxjumps = 2; //Max amount of Jumps (Double Jump)
float jumpforce = 7.75f; //Force going up (Y axis)
bool grounded = true; //Start Grounded

public int jumps;
int maxjumps = 2;
float jumpforce = 7.75f;
bool grounded = true;
public GameObject door = GameObject.FindGameObjectWithTag("Door"); //Public so I could drag door in, not sure I need to find with tag but leaving as it works

void Start()
{
rb = GetComponent<Rigidbody2D>(); //Get rigidbody component from player
door.SetActive(false); // Turn off the door
}

void Update()
Expand All @@ -24,47 +29,50 @@ void Update()
Vector3 movement = new Vector3(moveHorizontal, 0.0f, 0.0f); //No movement in the Y or Z Axies
transform.position += movement * Time.deltaTime * speed; //Transform the position in accordance to movement, times speed, times time passed

if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.W))
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.W)) //Player wants to Jump
{
Jump();
Jump(); //Go to Jump
}
}

void Jump()
{
if (jumps > 0)
if (jumps > 0) //if there are jumps available
{
rb.AddForce(new Vector2(0, jumpforce), ForceMode2D.Impulse);
grounded = false;
jumps = jumps - 1;
rb.AddForce(new Vector2(0, jumpforce), ForceMode2D.Impulse); //then jump
grounded = false; //off the ground
jumps = jumps - 1; //used a jump
}
if (jumps == 0)
if (jumps == 0) //there are no jumps
{
return;
return; // do nothing
}
}


void OnCollisionEnter2D(Collision2D collide)
void OnCollisionEnter2D(Collision2D collide) //Floor Collision
{
if (collide.gameObject.tag == "Box")
if (collide.gameObject.tag == "Box") //if you land on box then you have your jumps back
{
jumps = maxjumps;
grounded = true;
jumps = maxjumps; //2
grounded = true; //on ground
}
}

void OnTriggerEnter2D(Collider2D other)
void OnTriggerEnter2D(Collider2D other) //Pickups
{
if (other.gameObject.CompareTag("Key"))
if (other.gameObject.CompareTag("Key")) //If you got the key
{
other.gameObject.SetActive(false);
other.gameObject.SetActive(false); //key is not actice
door.SetActive(true); // Door is accessible
}

if (other.gameObject.CompareTag("Cash"))
{
other.gameObject.SetActive(false);
other.gameObject.SetActive(false); // cash dissapears
//Add money
}

}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1fdc606

Please sign in to comment.