-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ive been working all day and havent pushed in a while
- Loading branch information
Showing
44 changed files
with
6,754 additions
and
5,600 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
Platformer/Assets/Scripts/Player&Enemy/Player_Controller.cs.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
[RequireComponent(typeof(Controller2D))] | ||
public class Player_Controller : MonoBehaviour | ||
{ | ||
Controller2D controller; //controller | ||
|
||
float moveSpeed = 10; //How Fast He moves | ||
|
||
|
||
float gravity; //Gravity (No Rigid Body) | ||
float jumpVelocity; | ||
Vector3 velocity; //Velocity (Again since using raycasting need to create alll this) | ||
float velocityXSmoothing; | ||
|
||
//Jumping | ||
public float jumpHeight = 4; //height | ||
public float timeToJumpApex = .4f; //time to get there | ||
float accelerationTimeAirborne = .2f; //acceleration time | ||
float accelerationTimeGrounded = .15f; //time to | ||
|
||
|
||
public int currentHealth; //health | ||
private int maxHealth = 100; //max health | ||
public HealthBar healthbar; //Healthbar | ||
|
||
public GameObject door; //Public so I could drag door in | ||
|
||
void Start() | ||
{ | ||
controller = GetComponent<Controller2D>(); //Get Components controller2d | ||
|
||
gravity = -(2 * jumpHeight) / Mathf.Pow(timeToJumpApex, 2); //Derived from equation | ||
jumpVelocity = Mathf.Abs(gravity) * timeToJumpApex; //Derived from equation | ||
print("Gravity: " + gravity + " Jump Velocity: " + jumpVelocity); | ||
|
||
door.SetActive(false); // Turn off the door | ||
currentHealth = maxHealth; //Reset to max health | ||
healthbar.SetMaxHealth(maxHealth); //Health bar to max | ||
} | ||
|
||
void Update() | ||
{ | ||
if (controller.collisions.above || controller.collisions.below) //if true reset y | ||
{ | ||
velocity.y = 0; | ||
} | ||
|
||
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); | ||
|
||
if (Input.GetKeyDown(KeyCode.Space) && controller.collisions.below) //Jumping (and on something) | ||
{ | ||
velocity.y = jumpVelocity; | ||
} | ||
|
||
float targetVelocityX = input.x * moveSpeed; | ||
|
||
velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne); //Movement in the x direction | ||
velocity.y += gravity * Time.deltaTime; //Movement in the y Direction | ||
controller.Move(velocity * Time.deltaTime); //How to actually move, in controller script | ||
} | ||
|
||
|
||
//Damage Function | ||
void TakeDamage(int damage) | ||
{ | ||
currentHealth -= damage; //take damage | ||
healthbar.SetHealth(currentHealth); //modify health bar | ||
if (currentHealth < 1) | ||
{ | ||
Time.timeScale = 0f; | ||
} | ||
} | ||
|
||
|
||
|
||
//Ontrigger Enter (AKA TAGS) | ||
void OnTriggerEnter2D(Collider2D other) //Pickups | ||
{ | ||
if (other.gameObject.CompareTag("Key")) //If you got the key | ||
{ | ||
other.gameObject.SetActive(false); //key is not actice | ||
door.SetActive(true); // Door is accessible | ||
} | ||
|
||
if (other.gameObject.CompareTag("Heart")) | ||
{ | ||
other.gameObject.SetActive(false); // heart dissapears | ||
currentHealth = maxHealth; // Full Health | ||
healthbar.SetHealth(currentHealth); //Full HealthBar | ||
} | ||
|
||
if (other.gameObject.CompareTag("Enemy")) | ||
{ | ||
TakeDamage(20); | ||
} | ||
|
||
//Ninja star is in the weapon script (easier that way for some reason ) | ||
} | ||
|
||
|
||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.