I have a screen with two objects 2d: player
and enemy
, both are prefab
of an object called fighter
.
They have three properties: attack
, defense
and hp
.
I created a script and included it in the camera, it is who will control the game.
I want to know how to make the camera script decrease the hp
of one of my objects.
Class fighter
:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class fighter: MonoBehaviour {
public int attack;
public int defense;
public int hp;
public int mp;
// Use this for initialization
void Start () {
int range = Random.Range (150, 200);
attack = range;
range = Random.Range (100, 150);
defense = range;
range = Random.Range (800, 1000);
hp = range;
}
// Update is called once per frame
void Update () {
}
}
Class in camera:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class turnBased : MonoBehaviour {
private BattleStates currentState;
// Use this for initialization
void Start () {
}
void Update() {
}
void OnGUI(){
if (GUILayout.Button ("ATTACK")) {
//crio um botão e ao ser clicado, deve causar dano ao inimigo
enemy.hp -= 10; //<<<<aqui deve vir o código
}
}
}