I am having trouble accessing a variable from another script for a game I am making the variable is on a script called activateShield and it is used to check the shield in another script…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ActivateShield : MonoBehaviour {
public ParticleSystem part1;
public bool status = false;
public int Strength;
public int scoreValue;
public GameObject explosion;
public GameObject playerExplosion;
// Use this for initialization
// Update is called once per frame
private void Awake()
{
part1.Clear();
}
void Update()
{
if (Input.GetButton("Submit"))
{
var emission = part1.emission;
emission.enabled = true;
status = true;
// shieldsup = true;
Debug.Log("shield is true");
return;
}
else if (!Input.GetButton("Submit"))
{
var emission = part1.emission;
part1.Clear();
status = false;
Debug.Log("shield is false");
}
}
}
and is called by Destroy on contact
using UnityEngine;
using System.Collections;
public class Done_DestroyByContact : MonoBehaviour
{
public ActivateShield shield;
public GameObject explosion;
public GameObject playerExplosion;
public int scoreValue;
private Done_GameController gameController;
void Start()
{
GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent<Done_GameController>();
}
if (gameController == null)
{
Debug.Log("Cannot find 'GameController' script");
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Boundary" || other.tag == "Enemy")
{
return;
}
if (explosion != null)
{
Instantiate(explosion, transform.position, transform.rotation);
}
if ((other.tag == "Player") && (shield.status == true)){
shield.Strength--;
return;
}
else if (( other.tag == "Player" ) && (shield.status == false))
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameController.GameOver();
}
gameController.AddScore(scoreValue);
Destroy(other.gameObject);
Destroy(gameObject);
}
}
for the life of me I don’t know why I cant acess member vars…
David