Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Ego65 · May 18, 2016 at 04:22 PM · clickmouseclickfunction update

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

53 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges