- Home /
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).
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;
}
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.
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'
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
![](https://koobas.hobune.stream/wayback/20220613080903im_/https://answers.unity.com/themes/thub/images/avi.jpg)