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 mariosep · Aug 07, 2013 at 08:14 AM · guishop

How to debug this shopkeeper script ?

Hello, I am making a RPG game but as I am new to unity then I stumbled on a problem that I cannot figure out myself. I made a shopkeeper script that would work for many shopkeepers. The problem is that when I click different shopkeepers they all give the same layout of items although I have but different numbers for the script on different shopkeepers. At the beginning I thought that it isn't working at all but then I realized that although the layout is always the same the items are as I put them for every shopkeeper. So it kinda works only the layout of items has the problem.

 var hit : RaycastHit;
 static var shopOpen : boolean = false;
 var texture : Texture2D;
 var shopSize = Rect(50, 50, 400, 500);
 var items : int[]; //This is where I put the item numbers for every shopkeeper
 static var shopList : List.<ItemClass> = new List.<ItemClass>(); // this is where all the items for shops are listed
 var myTransform : Transform; //current transform data of this enemy
 var target : Transform;
 var shopDistance : int = 5;
 private var slotNR : int = 0;
 
 function Awake (){
     myTransform = transform; //cache transform data for easy access/preformance
 }
 
 function Start (){
     target = GameObject.FindWithTag("Player").transform; //target the player
 }
 
 function OnGUI () {
     if(shopOpen == true){
         shopSize = GUI.Window(3, shopSize, ShopWin, texture);
     }
 }
  
 function Update () {
     var distance = (target.position - myTransform.position).magnitude;
     if(distance < shopDistance){
         if(Input.GetMouseButtonDown(0) &&
                collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, Mathf.Infinity)) {
             //enable shop    
             shopOpen = true;
         }
     }
 //    if(distance > shopDistance){
 //        shopOpen = false;
 //    }
 }
 
 function ShopWin(){
     if(GUI.Button(Rect(375, 0, 25, 25), "X")){
         shopOpen = false;
     }
     // For recognizing the slot
     slotNR = 0;
     //y is row nr
     for(var y = 0; y < 2; y++){
         GUILayout.BeginHorizontal();
         //x is columnt nr
         for(var x = 0; x < 6; x++){
             xPosition = 12 + (x * 62);
             yPosition = 30 + (y * 62);
             //Shop slots. If clicked they check what item it is in the slot and then corresponds to it
             if(GUI.Button(Rect(xPosition, yPosition, 60, 60), shopList[items[slotNR]].icon)){
                 Inventory.Coins -= 50;
                 Inventory.playerInventory.Add(shopList[items[slotNR]]);
                 return;
             }
             slotNR++;
         }
         GUILayout.EndHorizontal();
     }
 
     GUI.DragWindow();
 }

I would be very thankful for any kind of hints :)

Comment
Add comment · Show 5
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 nixcs2512 · Aug 07, 2013 at 08:42 AM 0
Share

It just because you put a "static" type of List, that means all your shop keeper will store the same information about how much items would be sold, the prices, and amounts,... , and believe me, if you bought all things from one store, you wouldn't see anything in other stores.

avatar image mariosep · Aug 07, 2013 at 09:07 AM 0
Share

But there is a list of items(numbers) that will be different for each shop. And because of these numbers I can choose what I want to sell in what shop. it is just that the icons are the same. Even at the moment I can buy different things from different shops just that I need a way that the icons would be refreshed when I open another shop. :) And making a different script or list for every shop would be kind of wasting the resources, or am I wrong ?

avatar image nixcs2512 · Aug 07, 2013 at 09:39 AM 0
Share

Think about resources here is too soon. But if that's your idea, my suggestion is only about making a new script that store informations about what to sell in each shop, and your shopList will get information from that ins$$anonymous$$d of making it static so every shop sell the same things at the same time

avatar image mariosep · Aug 07, 2013 at 03:46 PM 0
Share

Okay. I will try it this way. Thank you for answering :)

avatar image lancer · Aug 10, 2013 at 05:07 PM 0
Share

@$$anonymous$$ariosep

Could I have your player inventory script? And your ItemClass script? I'd like to see how they work since I'm making a game that has this kind of stuff.

0 Replies

· Add your reply
  • Sort: 

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

15 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Make GUI.TextArea show up only when Left Ctrl pressed 1 Answer

Colliders with JS only 2 Answers

'Back to Main Menu' button works, but cannot click menu buttons after returning! 1 Answer

How do you CORRECTLY call methods from another C# file 1 Answer


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