Permalink
Cannot retrieve contributors at this time
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?
Intro_Scritping/Test_CYOA/Assets/Scripts/Combat.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
146 lines (115 sloc)
3.02 KB
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
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; | |
public GameObject gunLabel; | |
//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; | |
gunLabel.SetActive(true); | |
} | |
} | |
} | |
//HP Display | |
hpText.text = "health: " + hpValue; | |
//Fail State | |
if (hpValue <= 0) | |
{ | |
Application.LoadLevel("CYO_Layout"); | |
} | |
} | |
} |