Skip to content
Permalink
aee962d2c7
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
110 lines (91 sloc) 2.44 KB
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PlayerPhysics))]
public class PlayerController : MonoBehaviour {
public float gravity = 20;
public float PlayerSpeed = 6;
//public float acceleration;
public float jumpHeight = 12;
//public GameObject portal;
private Vector3 mousePos;
[HideInInspector]
public bool pDead = false;
private Vector2 movement;
private float playerHP = 1;
public GameObject WeaponPortal;
private PlayerPhysics playerPhysics;
private bool portalExist = false;
private GameObject currentPortal;
private bool gotHit=false;
private bool gotPower=false;
void Start () {
playerPhysics = GetComponent<PlayerPhysics>();
}
void OnGUI(){
if (gotHit){
GUI.TextField (new Rect (0, 0, 90, 20), "Hit by enemy!", 25);
}
if (gotPower){
GUI.TextField (new Rect (0, 0, 60, 20), "Powerup!", 25);
}
}
void OnTriggerEnter(Collider other) {
string derp = other.tag;
if (derp == "Powerup"){
gotPower=true;
Invoke ("resetPower", 1f);
playerHP++;
//Debug.Log ("Powered up!");
}
else if (derp == "EndPortal"){
DestroyObject (this.gameObject);
//Debug.Log ("hit portal");
}
else if (derp == "Backboard"){}
else{
gotHit=true;
Invoke ("resetHit", 1f);
playerHP--;
//Debug.Log ("phit");
}
}
void resetHit(){
gotHit=false;
}
void resetPower(){
gotPower=false;
}
void playerDead() {
DestroyObject(this.gameObject);
pDead = true;
}
void Update () {
if (playerHP <= 0) {
playerDead ();
}
float amtToMove = Input.GetAxisRaw ("Horizontal") * PlayerSpeed * Time.deltaTime;
if(playerPhysics.grounded) {
movement.y = 0;
if(Input.GetButtonDown ("Jump")) {
movement.y = jumpHeight;
}
}
movement.x = amtToMove;
movement.y -= gravity * Time.deltaTime;
playerPhysics.move (movement);
CastRayToWorld ();
if(Input.GetMouseButtonDown(0)){
if (portalExist) {DestroyObject(currentPortal.gameObject);}
//Vector3 position = new Vector3(transform.position.x, transform.position.y + (transform.localScale.y / 2), 0);
currentPortal = (Instantiate (WeaponPortal, mousePos, Quaternion.identity) as GameObject);
portalExist = true;
//Debug.Log (mousePos);
}
}
void CastRayToWorld() {
Ray ray= Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 point= ray.origin + (ray.direction);
mousePos = new Vector3(point.x, point.y, 0.0f);
//Debug.Log( "World point " + pointZero);
}
}