Quantcast
Channel: Questions in topic: "get"
Viewing all articles
Browse latest Browse all 215

How to get a value set by another script?

$
0
0
So basically I have a script attached to objects that when they are pressed on it deletes them and adds 1 to a GUItext counter. I'm doing this with var PageCount : GUIText; var Count : int; var Pickup : AudioClip; function Touched(hit:RaycastHit) { Destroy(gameObject); } function Update () { if ( Input.GetMouseButtonDown(0)){ var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, hit, 0.8)) { hit.transform.SendMessage("Touched", hit, SendMessageOptions.DontRequireReceiver); Count ++; PageCount.guiText.text = Count.ToString(); audio.PlayOneShot(Pickup); if(Count >= 3){ Application.LoadLevel(2); } } } } But I like to keep my scripts tidy so I have scripts for independent things, I want to have another script that controls the enemies rate of spawn to increase a different level each time an item is collected. So for example when the pagecount = 1 I want the enemy to spawn at a rate of 8 but when pagecount = 2 I want him to spawn at say 5. Since my enemy spawn is in an entirely different script how would I go about getting the value of pagecount and using it in an if statement?

Viewing all articles
Browse latest Browse all 215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>