So i have 2 scripts (and more) who do some stuff with blocking and hitbox.
using UnityEngine;
using System.Collections;
public class Block : MonoBehaviour
{
public bool IsBlocking;
public float blockcooldown = 2F;
public void Awake ()
{
}
void Update ()
{
blockpress ();
blockstate ();
}
public void blockpress()
{
if (Input.GetButton ("Fire2") && blockcooldown >= 2F) {
IsBlocking = true;
blockcooldown = 0F;
Renderer[] rs = GetComponentsInChildren<Renderer> ();
foreach(Renderer r in rs)
r.enabled =true;
}
else {
blockcooldown += Time.deltaTime;
}
}
public void blockstate()
{
if (blockcooldown >= 1.1F)
{
Renderer[] rs = GetComponentsInChildren<Renderer> ();
foreach(Renderer r in rs)
r.enabled = false;
IsBlocking = false;
}
}
}
and
using UnityEngine;
using System.Collections;
public class HitBox : MonoBehaviour {
private HP hp;
private Block block;
private SwordAttack sw;
void Awake()
{
block = new Block ();
sw = new SwordAttack ();
hp = new HP ();
}
void Update()
{
block.blockpress ();
//block.blockstate ();
Debug.Log (block.IsBlocking);
}
void OnTriggerEnter(Collider other)
{
if (block.IsBlocking == true) {
Debug.Log ("Block true and cd -0.5");
sw.attackcooldown = 1F;
}
if (block.IsBlocking == false) {
Debug.Log ("Block false and hp -1 ");
hp.health--;
Debug.Log ("Health now is " + hp.health);
hp.CheckHealth ();
}
}
}
So i when i read the IsBlocking state in it’s own script it is true but when i read it in HitBox it is always false (the state it is originaly defined at). Can someone write a example on how you would approach this problem? Do i need to read it from the object it is attached to?
Block is attached to “BlockEffect” object and HitBox is attache to “HITBOX” object. Will go to sleep soon so i hope for an answer.