Skip to content
Permalink
ef75701f85
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
144 lines (113 sloc) 2.95 KB
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Combat : MonoBehaviour {
//Click References
public Ray ray;
public RaycastHit hit;
//Text Variables
public static int hpValue;
Text hpText;
//Game Objects
public GameObject enemy1;
public GameObject enemy2;
//Combat Variables
public int damage = 25;
public int damageEnemy = 25;
public int xp = 0;
public int enemy1HP = 75;
public int enemy2HP = 100;
//Collectables
public GameObject healthPickup;
public GameObject xpCube;
public GameObject gunPickup;
//Initiate Game Stuff
void Awake()
{
hpText = GetComponent<Text>();
hpValue = 100;
}
void Update()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//Combat
if (Physics.Raycast(ray, out hit))
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (hit.transform.name == "Enemy1")
{
hpValue = hpValue - damageEnemy;
enemy1HP = enemy1HP - damage;
Debug.Log("attack registered");
}
}
}
if(enemy1HP <= 0)
{
Destroy(enemy1);
}
if (Physics.Raycast(ray, out hit))
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (hit.transform.name == "Enemy2")
{
hpValue = hpValue - damageEnemy;
enemy2HP = enemy2HP - damage;
Debug.Log("attack registered");
}
}
}
if (enemy2HP <= 0)
{
Destroy(enemy2);
}
//Level Up
if (Physics.Raycast(ray, out hit))
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (hit.transform.name == "XPCube")
{
Destroy(xpCube);
xp = 1; }
}
}
if(xp > 0)
{
damageEnemy = 12;
}
//HP Pickup
if (Physics.Raycast(ray, out hit))
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (hit.transform.name == "HealthKit")
{
Destroy(healthPickup);
hpValue = hpValue + 30;
}
}
}
//Mega Gun
if (Physics.Raycast(ray, out hit))
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (hit.transform.name == "MegaGun")
{
Destroy(gunPickup);
damage = 100;
}
}
}
//HP Display
hpText.text = "health: " + hpValue;
//Fail State
if (hpValue <= 0)
{
Application.LoadLevel("CYO_Layout");
}
}
}