Thursday, April 28, 2016
PlayerHealth Script
PlayerHealth:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerHealth : MonoBehaviour
{
public
int startingHealth = 100; // The amount of health the player starts the game
with.;
public
int currentHealth; // The current
health the player has.
public
Slider healthSlider; // Reference to
the UI's health bar.
public
Image damageImage; // Reference to
an image to flash on the screen on being hurt.
public
AudioClip deathClip; // The audio
clip to play when the player dies.
public
float flashSpeed = 5f; // The speed
the damageImage will fade at.
public
Color flashColour = new Color(1f, 0f, 0f, 0.1f); // The colour the damageImage is set to, to
flash.
float
healthTimer = 0.0f;
bool
healthPackShouldRespawn = false;
public
GameObject healthPack;
Animator
m_animator; // Reference to
the Animator component.
AudioSource
m_playerAudio; // Reference to
the AudioSource component.
PlayerMovement
m_playerMovement; // Reference to the
player's movement.
PlayerShooting
m_playerShooting; // Reference to the
PlayerShooting script.
bool
isDead; // Whether the player is dead.
bool
damaged; // True
when the player gets damaged.
void Awake ()
{
//
Setting up the references.
m_animator =
GetComponent <Animator> ();
m_playerAudio
= GetComponent <AudioSource> ();
m_playerMovement = GetComponent <PlayerMovement> ();
m_playerShooting = GetComponentInChildren <PlayerShooting> ();
//
Set the initial health of the player.
currentHealth
= startingHealth;
//InvokeRepeating
("PlayerHealthPack", 5,1);
}
void Update ()
{
//
If the player has just been damaged...
if
(damaged)
{
damageImage.color
= flashColour;
}
//
Otherwise...
else
{
//
... transition the colour back to clear.
damageImage.color
= Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
}
//
Reset the damaged flag.
damaged
= false;
if
(healthPackShouldRespawn)
{
healthTimer
+= Time.deltaTime;
if
(healthTimer > 20.0f)
{
healthPack.gameObject.SetActive
(true);
healthTimer
= 0.0f;
}
}
}
public void
TakeDamage (int amount)
{
//
Set the damaged flag so the screen will flash.
damaged
= true;
//
Reduce the current health by the damage amount.
currentHealth
-= amount;
//
Set the health bar's value to the current health.
healthSlider.value
= currentHealth;
//
Play the hurt sound effect.
m_playerAudio.Play
();
//
If the player has lost all it's health and the death flag hasn't been set
yet...
if(currentHealth
<= 0 && !isDead)
{
Death ();
}
}
void
OnTriggerEnter(Collider item)
{
if(item.gameObject.tag
== "PlayerHealthPack")
{
if(currentHealth
< 100)
{
currentHealth
= currentHealth + 10;
healthSlider.value
= currentHealth;
item.gameObject.SetActive(false);
healthPackShouldRespawn
= true;
}
}
}
void Death ()
{
//
Set the death flag so this function won't be called again.
isDead
= true;
//
Turn off any remaining shooting effects.
m_playerShooting.DisableEffects
();
//
Tell the animator that the player is dead.
m_animator.SetTrigger
("Die");
//
Set the audiosource to play the death clip and play it (this will stop the hurt
sound from playing).
m_playerAudio.clip
= deathClip;
m_playerAudio.Play ();
//
Turn off the movement and shooting scripts.
m_playerMovement.enabled
= false;
m_playerShooting.enabled = false;
}
public void
RestartLevel ()
{
Application.LoadLevel (Application.loadedLevel);
}
}
EnemyAttack Script (Computer Aspect) (Close Attack)
EnemyAttack:
using UnityEngine;
using System.Collections;
public class EnemyAttack : MonoBehaviour
{
public
float timeBetweenAttacks = 0.5f; //
The time in seconds between each attack.
public
int attackDamage = 10; //
The amount of health taken away per attack.
Animator
m_animator; //
Reference to the animator component.
Animator
m_lightAttack; // Reference to the animator component.
Animator
m_DoNotAttack; //
Reference to the animator component.
GameObject
m_player; //
Reference to the player GameObject.
//GameObject
m_enemy; //
Reference to the enemy GameObject.
PlayerHealth
m_playerHealth; // Reference
to the player's health.
EnemyHealth
m_enemyHealth; //
Reference to this enemy's health.
bool
playerInRange; //
Whether player is within the trigger collider and can be attacked.
float
timer; // Timer for counting up to
the next attack.
void Awake ()
{
//
Setting up the references.
m_player =
GameObject.FindGameObjectWithTag ("Player");
m_playerHealth
= m_player.GetComponent <PlayerHealth> ();
m_enemyHealth =
GetComponent<EnemyHealth>();
m_animator =
GetComponent <Animator> ();
m_lightAttack
= GetComponent <Animator> ();
m_DoNotAttack
= GetComponent <Animator> ();
}
void
OnTriggerEnter (Collider other)
{
//
If the entering collider is the player...
if(other.gameObject
== m_player)
{
//
... the player is in range.
playerInRange
= true;
}
}
void OnTriggerExit
(Collider other)
{
//
If the exiting collider is the player...
if(other.gameObject
== m_player)
{
//
... the player is no longer in range.
playerInRange
= false;
}
}
void Update ()
{
//
Add the time since Update was last called to the timer.
timer
+= Time.deltaTime;
//
If the timer exceeds the time between attacks, the player is in range and this
enemy is alive...
if
(timer >= timeBetweenAttacks && playerInRange &&
m_enemyHealth.currentHealth > 0)
{
Attack
();
}
else
if (!playerInRange)
{
DoNotAttack
();
}
//
If the player has zero or less health...
if(m_playerHealth.currentHealth
<= 0)
{
m_animator.SetTrigger ("PlayerDead");
m_lightAttack.SetTrigger
("PlayerDead");
}
}
void Attack ()
{
//
Reset the timer.
timer
= 0f;
//
If the player has health to lose...
if(m_playerHealth.currentHealth
> 0)
{
//
... Attack the player.
m_lightAttack.SetTrigger
("LightAttack");
}
}
void
DamagePlayer()
{
//Damage
the player.
m_playerHealth.TakeDamage
(attackDamage);
}
void
DoNotAttack ()
{
m_DoNotAttack.SetBool
("DoNotAttack", false);
}
}
Wednesday, April 27, 2016
Tuesday, April 26, 2016
Thursday, April 21, 2016
Wednesday, April 20, 2016
Tuesday, April 19, 2016
Google Doc
Put files you want to share with the group in here
https://drive.google.com/drive/folders/0B_H1X-0DsSBUWWpfVHdUQTFDNEk
https://drive.google.com/drive/folders/0B_H1X-0DsSBUWWpfVHdUQTFDNEk
Forest environment and volcano sample
Thursday, April 14, 2016
Student's weekend task's
Etienne: Getting attacks to function
Simon: Working on the game manger
Allen: Working on the networking
Wallace: Working on the camera
Chelsea: Working on the spread sheet
Irvin: Working on the arena
Simon: Working on the game manger
Allen: Working on the networking
Wallace: Working on the camera
Chelsea: Working on the spread sheet
Irvin: Working on the arena
Tuesday, April 12, 2016
week 2
examples of art ideas
the style is of the game is fantasy chibi with each character having one specific weapon.
right now the artists will be working on the background of the game and the sprite sheets for the characters.
Thursday, April 7, 2016
week 1
we have decided to do an arena based game with fighting, artists are working on the concept art. still working on a theme for the game. programmers are working on mechanics for the game, how the characters are going to fight and what not. next class we will finalize everything and get started on the project.
Subscribe to:
Posts (Atom)
























