Professional Documents
Culture Documents
Player Behaviour - Cs
Player Behaviour - Cs
using System.Collections;
public class Player_Behaviour : MonoBehaviour {
//Right or Left Mouse Buttom Skill
public int RMBS = 1;
public int LMBS = 1;
//0 = basic attack
//1 = blue magic
//2 = lightining
//3 = force wave
//4 = heal
//5 = blink
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
GameObject
GameObject
GameObject
GameObject
_Footstep;
_Jump;
_DoubleJump;
_Magical_tTleport;
_Dash;
//Pause
public Pauser pause;
public float timer = 0;
//Damage
public GameObject damage_show;
// Use this for initialization
void Start () {
animator = playerTransform.GetComponent<Animator> ();
pause = GameObject.FindObjectOfType<Pauser>();
}
// Update is called once per frame
void Update () {
if (isLife) {
move ();
AddjustCurrentHealth ();
AddjustCurrentMana ();
AddjustCurrentStamina ();
instantiated_Enemies ();
} else {
timer +=Time.deltaTime;
if(timer > 1f)
{
pause.paused = true;
}
if (Input.GetKeyDown (KeyCode.R)) {
Game_Behaviour.reset();
Application.LoadLevel("GoodRage");
}
if(Input.GetKeyDown(KeyCode.E)){
Game_Behaviour.reset();
Application.LoadLevel("GoodRage_Main_Screen");
}
}
}
//Controle Da Mana
public void AddjustCurrentMana() {
time_Regen_Mana += Time.deltaTime;
if (rate_Regen_Mana < time_Regen_Mana) {
time_Regen_Mana = 0;
if(mana<maxMana)
{
if((mana+mana_regen) > maxMana)
mana = maxMana;
else
mana += mana_regen;
}
}
if (mana > maxMana)
{
mana = maxMana;
}
}
//Controle da Stamina
public void AddjustCurrentStamina() {
time_Regen_Stamina += Time.deltaTime;
if (rate_Regen_Stamina < time_Regen_Stamina) {
time_Regen_Stamina = 0;
if(stamina<maxStamina)
{
if((stamina+stamina_regen) > maxStamina)
stamina = maxStamina;
else
stamina += stamina_regen;
}
}
}
//Controle Da Vida
public void AddjustCurrentHealth() {
time_Regen_Health += Time.deltaTime;
if (rate_Regen_Health < time_Regen_Health) {
time_Regen_Health =0;
if (health<maxHealth){
if ((health+health_regen) > maxHealth){
health=maxHealth;
}
else {
health+=health_regen;
}
}
}
if (health <= 0)
{
health = 0;
Die();
}
if (health > maxHealth)
{
health = maxHealth;
}
}
//Controle de Dodge
public void AddjustCurrentDodge() {
time_Regen_Dodge += Time.deltaTime;
if (rate_Regen_Dodge < time_Regen_Stamina) {
time_Regen_Dodge = 0;
if(dodge<maxDodge)
{
if((dodge+dodge) > maxDodge)
dodge = maxDodge;
else
dodge += dodge_regen;
}
}
}
//Cotrole da Morte
public void Die(){
//Nao implemtentada ainda no aguardo
//print("Die");
animator.SetTrigger("Die");
isLife = false;
}
//Controle Do Movimento
}
//Salto e evitar o doble jump
if (Input.GetButtonDown ("Jump")&& isGrouded && !jumped) {
rigidbody2D.AddForce(transform.up*force);
jumpTime = jumpDelay;
animator.SetTrigger("Jump");
jumped =true;
//Audio do salto
audio.clip = _Jump;
audio.Play();
}
jumpTime -= Time.deltaTime;
if (jumpTime <= 0 && isGrouded && jumped) {
animator.SetTrigger("Ground");
jumped= false;
doublejump=true;
}
//Salto duplo
if (Input.GetButtonDown ("Jump") && !isGrouded && jumped && doub
lejump) {
rigidbody2D.AddForce(transform.up*force);
animator.SetTrigger("DoubleJump");
doublejump=false;
//Audio do double jump
audio.clip = _DoubleJump;
audio.Play();
}
//Ataque simples
if ((Input.GetButtonDown("Fire1") && LMBS == 0) || (Input.GetBut
tonDown("Fire2")&& RMBS == 0)) {
animator.SetTrigger("Atack");
}
//Ataque magico
if ((Input.GetButtonDown("Fire1") && LMBS == 1) || (Input.GetBut
tonDown("Fire2")&& RMBS == 1) && mana >0){
animator.SetTrigger("Magic");
Instantiate(magic,transform.position+ new Vector3(0,0.5f
,0),transform.rotation);
mana-=1;
}
//Ataque magico para teste shock wave
if (((Input.GetButtonDown("Fire1") && LMBS == 3) || (Input.GetBu
ttonDown("Fire2")&& RMBS == 3)) && (mana == maxMana)) {
Instantiate(magic_aura,transform.position,transform.rota
tion);
mana =0;
}
// Magia Blink
if ((Input.GetButtonDown("Fire1") && LMBS == 5) || (Input.GetBut
tonDown("Fire2")&& RMBS == 5)) {
Blink();
}
//Magia Heal
if ((Input.GetButtonDown("Fire1") && LMBS == 4) || (Input.GetBut
tonDown("Fire2")&& RMBS == 4)) {
Heal();
}
// Ataque de raios varios alvos
if ((Input.GetButtonDown("Fire1") && LMBS == 2) || (Input.GetBut
tonDown("Fire2")&& RMBS == 2)){
lighting();
}
}//Fim da move
// nova magia Blink para o mouse Gasta 1 de mana por distancia;
void Blink(){
Vector2 posirionrelative =Camera.main.ScreenToWorldPoint(Input.m
ousePosition);
float distancerelative = Vector2.Distance (posirionrelative, tr
ansform.position);
if (mana > distancerelative*10) {
transform.position = (posirionrelative);
mana -=(int) (distancerelative *10);
audio.clip = _Magical_tTleport;
audio.Play();
}
}
void Heal(){
if (mana >= 10) {
Instantiate(heal,transform.position,transform.rotation);
Hurt(-10);
mana-=10;
}
}
//Dor muita dor ao ser atacado doooooorr!!!!!
public void Hurt(int damageTaken){
if (health - damageTaken < 0) {
health = 0;
}else {
health-=damageTaken;
}
Vector3 relative = transform.position;
Quaternion relative2 = new Quaternion();
relative2.x = 0;
relative2.y = 0;
relative2.z = 0;
relative.y += Random.Range(1f,1.5f);
relative.x += Random.Range(-750f,750f)/1000f;
TextMesh texto = damage_show.GetComponent<TextMesh> ();
Color cor = new Color();
cor.r = 255f;
cor.g = 255f;
cor.b = 0f;
if (damageTaken < 0) {
cor.r = 0f;
damageTaken = 0 - damageTaken;
}
texto.text = "" + damageTaken + "";
cor.a = 255f;
texto.color = cor;
Instantiate (damage_show, relative,relative2);
}
public void instantiated_Enemies (){
gos = GameObject.FindGameObjectsWithTag("Enemy");
}
public void lighting(){
bool enemydetected = false;
//animator.SetTrigger("Magic_Lighting");
foreach (GameObject go in gos) {
if(go != null){
target = go.transform.position;
if(Vector3.Distance(this.transform.position,targ
et) < magic_Lightning.GetComponent<Magic_Player_Behaviour> ().range){
if((mana-3)>= 0)
{
enemydetected = true;
Instantiate(magic_Lightning,targ
et,transform.rotation);
mana-=3;
}
}
}
}
if(enemydetected)
{
animator.SetTrigger("Magic2");
}