|
Ok so what i have is 2 seperate scenes. The actual "game scene" where you kill things and pickup points. I have it so that once you have picked up all the points in that scene you will go to the Shop Menu through Application.LoadLevel. In the shop menu right now there is 1 button which i am trying to make it so that the variable of the "shoot" script in the "game scene" that determines how far you shoot will be increased if you have enough points. I also want that increase to stay on future levels like an upgrade. The errors I am getting with the ShopMenu script is Assets/Scripts/ShopMenu.js(15,34): BCE0020: An instance of type 'Points' is required to access non static member 'score'. Assets/Scripts/ShopMenu.js(17,35): BCE0020: An instance of type 'shoot' is required to access non static member 'gunRange'. My Shop Menu script is function OnGUI () { GUI.Box (Rect (10,10,250,90), "Shop Menu"); } function BuyRange() { }
(comments are locked)
|
|
I'm using static vars to hold things like points, lives, health etc. These variables are defined in a script called Control.js, and they may be accessed as Control.points, Control.health etc. This script is attached to my player (a FPS controller), and their static variables survive during the whole game: Another alternative is to keep these variables in a script assigned to an empty object, and include the DontDestroyOnLoad instruction in its Awake function: EDITED: If you want to use the static variable alternative, your scripts should look like below: The ShopMenu.js script: The shoot.js script: The Points.js script: oh ok i didnt quite know what static variable did. I changed the gunRange and points variables to static variables and fixed some of the code that was wrong in Shop Menu but now i get NullReferenceException ShopMenu.BuyRange () (at Assets/Scripts/ShopMenu.js:14) ShopMenu.OnGUI () (at Assets/Scripts/ShopMenu.js:9)
Jul 09 '11 at 04:31 PM
Airmand
A variable declared outside any function with var or public var is a public variable. It has script scope, what means that it's known by everybody in that script, but is a complete strange for other scripts. Static variables, on the other hand, have program scope, which means they are known by every script in the game. They also live during the whole game, even when a new level is loaded.
Jul 09 '11 at 05:54 PM
aldonaletto
Edited the answer to show how to use the static variables in your scripts. Remember that static variables are unique. If you have more than one TankTurret object, all of them will share the same gunRange, since it's a static variable now.
Jul 09 '11 at 06:25 PM
aldonaletto
im sorry i didnt even see the comments you were leaving. I believe the scripts you edited of mine work now. I just have to create a level 3 and see if the gunRange increased after it was bought
Jul 09 '11 at 07:57 PM
Airmand
and thank you for the explanation. it is much clearer now
Jul 09 '11 at 07:59 PM
Airmand
(comments are locked)
|
|
if(points = 100) { uprange up = (Range).GetComponent("Range"); eh.uprange(+10); } and in your ange class you should have uprange + range = currange
(comments are locked)
|
|
sorry im very new to coding and unity. What would my range class be. and im not sure how to read psuedocode. :P if(points = 100) // your if block............................................................................................................ uprange up = (Range).GetComponent("Range")// replace "Range" with the code name that has the range in it........................................................................................................................................................ eh.uprange(+10); // this adjusts the value of uprange.......................................................................... in the script where you have the range int. you should have uprange + range = cur.range;
Jul 09 '11 at 05:20 PM
Babilinski
i dont understand what uprange is
Jul 09 '11 at 05:32 PM
Airmand
its a variable that i made up . exp. your range is 5 then you go to the shop and you update your range buy 3 so 3 + 5 = currange AKA curent range
Jul 09 '11 at 05:37 PM
Babilinski
im sorry i just really dont know how to read your pseudocode. What is cur.range supposed to be?
Jul 09 '11 at 05:47 PM
Airmand
okay currange = a value that will change as the character gets more range. uprange = a value that will be the amount of range added to your currange after you have enough points range = a value that is the starting value of range when you start the game;
Jul 09 '11 at 05:53 PM
Babilinski
(comments are locked)
|
|
ok so i need to change the code in shop menu from if (pointsscore >= 15) { to if (pointsscore >=15) { uprange up = (Range).GetComponent("Range").uprange(+10); ? i really am not sure how to code the rest of what you said to do... do you have skype? ill show you
Jul 09 '11 at 06:22 PM
Babilinski
i can download it but i dont know how long it will take. Im currently in afgahnistan so my internet is a bit slower.
Jul 09 '11 at 06:34 PM
Airmand
(comments are locked)
|
1 2 next page »

sorry i dont know how to put code in properly i tried the greater pre lesser at the beginning of the scripts and the greater code lesser at the end of the scripts but that didnt work