Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Sylvir · Apr 02, 2015 at 05:54 PM · clicked

Can you use multiple click functions with one script?

trying to set up multiple click functions from one script, then add that script to the various game objects. I am trying to set up a script that checks if variable 1, in this case its called techpoints in my script. if they have 50 I want to be able to buy a virus and subtract those points. I got it working, but i realized that i had to keep inheriting back to check for the variables that i was using as the currency to purchase the new ones. I thought it might be easier to set it all up in one script, but when i did that nothing seems to work. I added the scrip to the 2 different game objects, and selected the different variables on each one. here is my script. can anyone tell me what im doing wrong, or if there is a much better way to do this?

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class BuildVirus : TPB  {
 
 
 //    public UnityEngine.UI.Text TPC;
     public UnityEngine.UI.Text TechPoints;
     public static float techPoints = 0.00f;
     public float techPointsPerClick = 1;
 //    private Slider mySlider;
 //    public float counter = 10.0f;
     public int click;
     public int VirusCost ;
 //    public VirusClick click;
   //  public UnityEngine.UI.Text vpc; 
     public UnityEngine.UI.Text VirusCount;
     public float virus  = 0.00f;
     public int virusPerClick = 1;
 
 
     void Start(){
 
     }
 
     void Update(){
 //        VirusCount.text = "Virus Count: " + virus;
 //        TechPoints.text = "Tech Points: " + techPoints;
     //    vpc.text = "VPC: " + virusPerClick;
         Debug.Log ("techPoints:" + techPoints);
     }
 
 
 
     public void Clicked(){
         VirusCost = 50;
     //    Debug.Log("techPoints before:"+techPoints);
             if(techPoints >= VirusCost){
             techPoints -= VirusCost;
 
             virus += 1;
             }
     //    Debug.Log("techPoints after:"+techPoints);
             
         }
 
     public void TechPointsClicked(){
         techPoints += techPointsPerClick;    
         {
 
     
     }
     }
 }

Comment
Add comment · Show 3
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
avatar image Sylvir · Apr 01, 2015 at 08:08 PM 0
Share

I was going through my game outline, and realized that it might work best if i just make one script that has all the variables defined, and then anytime i make a new one i can have it inherit from that first script, and then have the first one inharit monobehaviour, would that be the best option?

avatar image Sylvir · Apr 01, 2015 at 08:30 PM 0
Share

hmm.. that seems to still bring up all the options on the editor interface still. not sure, what do i try? lol

avatar image TxAg03 · Jun 26, 2015 at 09:51 PM 0
Share

To make variables public that you can access in other scripts but don't want to be visible in the editor, type this directly above the variable [HideInInspector].

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make a 2D object do something when clicked C# 1 Answer

make an object move when its clicked 1 Answer

Clicking problem 0 Answers

Show mouse click feedback on textured 2d plane button 2 Answers

Rotating an GameObject in a 2D plane based on clicking on a game object. 1 Answer


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