Scripts Trees.js and Melee.js connect variables that aren’t declared in both, however I can’t connect variable “Wood” from Inve.js to Trees.js, please explain what code is allowing Trees and Melee to connect and work properly, and I would appreciate it if someone could help me connect the Inve.js to Trees.js, I want Trees.js to be able to do this :
if(secondaryhealth <= 1) { Destroy (gameObject); Wood = Wood + 1;
////Inve.js
#pragma strict
var Inv = 0;
var Wood = 0;
var CANPlaceWood : boolean;
function Start ()
{var CANPlaceWood = false;}
function Update () {
if(Wood > 1) {var CANPlaceWood = true;}
}
///Trees.js
#pragma strict
var health = 150;
var secondaryhealth = 250;
function ApplyDamage (DamageAxe : int)
{
health -= DamageAxe;
}
function ApplyDamages (DamageAxe : int){
if(health <= 1)
{
secondaryhealth -= DamageAxe;
}
}
function Update ()
{
if(health <= 1) {if(health > -1) {animation.Play("TREEANIM");
-- health; } }
if(secondaryhealth <= 1) { Destroy (gameObject); Wood = Wood + 1; }
}
////Melee.js
#pragma strict
var DamageAxe : int = 50;
var Distance : float;
var MaxDistance : float = 1.25;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position,
transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{hit.transform.SendMessage("ApplyDamage",
DamageAxe, SendMessageOptions.DontRequireReceiver);}
} }
if (Input.GetButtonDown("Fire1"))
{
var hitt : RaycastHit;
if (Physics.Raycast (transform.position,
transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{hit.transform.SendMessage("ApplyDamages",
DamageAxe, SendMessageOptions.DontRequireReceiver);}
} }
}
Thanks for any help!