Shop

Updated on July 4, 2015 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
7 on July 3, 2015

Hello so iam making a shop i already made it like that 

#pragma strict
var nupirkta = false;
var Kaina : float;
var Kaina2 : float;
var CT : Texture2D;
var CT2 : Texture2D;
public var theObject : GameObject;
function OnTriggerEnter () {
if (GameMaster.currentScore == Kaina && nupirkta == false) {
GameMaster.currentScore -= Kaina;
theObject.GetComponent.().material.mainTexture = CT;
}
nupirkta = true;
if (GameMaster.currentScore == Kaina2) {
GameMaster.currentScore -= Kaina2;
theObject.GetComponent.().material.mainTexture = CT2;
}
}

so problem is i want to make a choice i already fixed the code about other problems soo can u tell me how to create something like windows witch will open on Trigger and will let u buy things via buttons

  • Liked by
Reply
6 on July 3, 2015

hello justasxz, do you mind being more specific? It’s kind of hard to tell what you’re trying to achieve.
Please put some screenshots of what your code is doing and maybe a mockup of what you’re trying to achieve

on July 3, 2015

to be specific i want to create code OnTriggerEnter witch will open Gui Interface witch has buttons in it and buttons will activate theese codes 

if (GameMaster.currentScore == Kaina2) {
GameMaster.currentScore -= Kaina2;
theObject.GetComponent.().material.mainTexture = CT2;
}

i need code to open Gui interface via javascript code thats all

Master
on July 4, 2015

ok, so, you want to make so when you enter a trigger a gui opens? That’s simple enough, just have a reference to the gameobject with the gui on it (probably a canvas object) and use code to SetActive(true) it when you enter the trigger.

You also want a gui that has buttons on it, that will activate certain codes?
personally, I haven’t used the new gui that much and am not too familiar with it, but check the Unity docs for the button class and see the examples they use there.

on July 4, 2015

ty i already figured a way to make it in another way i just created seperate shop screen with a bunch of buttons. But about that i got new problem xD my new problem is saving scores between scenes i tried this code 

#pragma strict
var GameMaster : GameMaster;
function OnTriggerEnter () {
Application.LoadLevel("level1");
DontDestroyOnLoad(GameMaster);
}

but the problem is because i need to persist same Gamemaster from game screen to shop and back to level it duplicates and bugs out … ( i need to keep money aka currentScore between scenes back and forth) it keeps it until shop but after i exit shop with this code that i posted above it doubles GameMaster and resets to 0

on July 4, 2015

well i used setactive as u told and it kidna works the way i want i just wanted buttons to be more organized thats all

Master
on July 4, 2015

to prevent it from duplicating, put in the Start() function a check to search and see if there’s an identical object already in the scene, and, if so, delete itself.

on July 4, 2015

so how do i check should i so something

var GameManager : GameManager; 
function Start () {
if (GameManager>2) {
Destroy(GameObject); 
}
}

yeah i know its incorrect it will give me rror game object cant be turnet into integer so tell me how to check for identical object

Show more replies
  • Liked by
Reply
Cancel