How to access a bool from buttonclick scr. into another script
hey at all,
i 've made a menu with buttons with which the player shall be able to upgrade settings like the damage strength of a laser projectile if he has enough points. So i made a Canvas = MyCanvas and attached the script "Spielende" in the OnClick() in the editor. To the Laserprojectile Upgrade button i set the function "Spielende.Stufe_1_Upgrade" in which a bool "Stufe_1_done = false" is changed to true if the player upgrades ( clicked button) the L_projectile. All this works well in the menu or if the buttons are clicked.
But how can i get it in the Script attached to the projectile prefab ? i tried to access it the classical way but that doesnt work.
here's the function in the script : Spielende
public void Stufe_1_Upgrade()
{
if(Stufe_1_done == true)
{
return;
}
else
{
if(Energy_Laser_Upgr_St_1.activeSelf && punktescript.Player_currentPlayerPoints >= Stufe_1 && Stufe_1_done == false)
{
punktescript.Player_currentPlayerPoints -= Stufe_1;
Stufe_1_done = true;
}
if(Stufe_1_done == true && Energy_Laser_Upgr_St_1.activeSelf)
{
Energy_Laser_Upgr_St_1.SetActive(false) ;
}
}
}
here's my script which is attached to the laser projectile in which i want to reset the value for damage
if the button is clicked
public class LaserProjectile : MonoBehaviour
{
public float speed = 2f;
public int damage = 25;
private Transform thisTransform;
//public Spielende thisscr;
//public GameObject thiscanvas;
//public Transform laserHitFXPrefab;
// Use this for initialization
void Start ()
{
thisTransform = transform;
}
// Update is called once per frame
void Update ()
{
thisTransform.position += Time.deltaTime * speed * thisTransform.forward;
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Enemy")
{
collision.gameObject.SendMessage ("TakeDamage", damage, SendMessageOptions.DontRequireReceiver);
ContactPoint contact = collision.contacts[0];
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
Vector3 pos = contact.point;
//Instantiate (laserHitFXPrefab, pos, rot );
Destroy (gameObject);
}
if (collision.gameObject.tag == "Asteroid")
{
collision.gameObject.SendMessage("TakeDamage", damage,SendMessageOptions.DontRequireReceiver);
ContactPoint contact = collision.contacts [0];
Quaternion rot = Quaternion.FromToRotation (Vector3.up, contact.normal);
Vector3 pos = contact.point;
Destroy (gameObject);
}
}
}
this prob is pretty new to me because i've just started working with menus
thx previously ( hope so much it isnt to complicated) :)
yours
Your answer
Follow this Question
Related Questions
Move only if mouse click the Terrain 0 Answers
Turn on and off sound on mouse click C# 1 Answer
Click detection suddenly stopped working 1 Answer
La touche "Fire1" ne marche pas 2 Answers
How to start animation of child 2 Answers