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 andrew95434 · Sep 11, 2012 at 04:59 AM · variablevaluestoreassign

assign value for all the script

how can i do that when i set a value for a variable, for example i have this script:

 using UnityEngine;
 using System.Collections;
 
 public class Cards : MonoBehaviour {
     
     bool start = false;
     string cardName;
     
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         
     }    
 
     void OnMouseOver() { 
         
         if(Input.GetMouseButtonDown(0)){    
             transform.rotation = Quaternion.AngleAxis(30,Vector3.up);
             start = true;
             cardName = gameObject.tag;            
         }
     }
 }    

and i want the "cardName" variable's value to get stored even after the if clause have finished, so i could use the variable with the value "gameObject.tag" (it will change after in my program).

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by svenskefan · Sep 11, 2012 at 05:40 AM

Hi! Not really sure what you are asking, but you could store the value in the Start function

    void Start(){
       cardName=gameObject.tag;
     }
Comment
Add comment · Show 1 · Share
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 andrew95434 · Sep 12, 2012 at 12:56 AM 0
Share

what i want is to assign the value inside the if clause, and when the if clause finishes, i want the value still having the same value i assigned inside the clause.

avatar image
0

Answer by DaveA · Sep 12, 2012 at 01:06 AM

How is this NOT working? Are you getting an error? What are you trying to accomplish? There is no point in storing gameObject.tag because it will not change. If you want to have a global variable that stores the current selected card, put 'static' in front of 'var' but really, it should be a different arrangement of things: a 'card manager' which keeps track of all cards, and a 'card select' script which manages the 'click'

Comment
Add comment · Show 1 · Share
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 andrew95434 · Sep 12, 2012 at 08:50 PM 0
Share

in my real script i inherit another script: "public class Cards : Camara", and what i want is to store the value in the other script, because the other script is in the main camera, so is common for all the objects, and i want to use the same value that was assigned in an object, but in other object.

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

10 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

Related Questions

Assign a random value to var personality" upon asset creation (Java) 1 Answer

How to return to a value used before? (C#) 1 Answer

cant assign variables value 2 Answers

Error: an exposed variable in a JavaScript is not a member of that script 1 Answer

Is "transform.position._" an expensive call? 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