Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 visalkoko · Dec 18, 2018 at 09:18 AM · prefabscrollviewshopobjectpool3dobject

Swipe to place order in ShopScrollList (prefabs, object pooling, instantiating)

I am building an Augmented Reality Food Project. I am trying to swipe the 3D object(food) to the Shop list for make the order of the food. Then, it should display the prefab for the object. The problem is I can't create new prefab at the second swipe of other 3D object. I mean that once I swipe one 3D Object, it should create one prefab in list and swipe other 3D Object, it also should create one more prefab on the same list. But how?

I follow the sample tutorials HERE

This swipe.cs script is attached to each 3D objects

Swipe.cs

 public Transform player; // Drag your player here
 public ShopScrollList shoplist;
 
 void Update ()
 {
         foreach(Touch touch in Input.touches)
         {
             if (touch.phase == TouchPhase.Began)
             {
                 fp = touch.position;
                 lp = touch.position;
             }
             if (touch.phase == TouchPhase.Moved )
             {
                 lp = touch.position;
                 swipeDistanceX = Mathf.Abs((lp.x-fp.x));
                 swipeDistanceY = Mathf.Abs((lp.y-fp.y));
             }
             if(touch.phase == TouchPhase.Ended)
             {
                 angle = Mathf.Atan2((lp.x-fp.x),(lp.y-fp.y))*57.2957795f;
                 if(angle > -30 && angle < 30 && swipeDistanceY > 40)
                 {
                     Debug.Log ("swipe");
                     player.position += new Vector3 (0, 0, 200);
                     if (player.name == "cupcake") {
                         shoplist.RefreshDisplay (player.name);
                     }
                     if (player.name == "friedegg") {
                         shoplist.RefreshDisplay (player.name);
                     }
                 }  

This ShopScrollList.cs is attached to the content panel

ShopScrollList.cs

 [System.Serializable]
 public class Item {
     public string itemName;
     public Sprite icon;
     public string price = 2 + "$";
 }
 
 public class ShopScrollList : MonoBehaviour {
 
     public List<Item> itemList;
     public Transform contentPanel;
     public Text myGoldDisplay;
     public SimpleObjectPool buttonObjectPool;
     private GameObject newButton;
 
 public void RefreshDisplay(string name)
 {
 RemoveButton();
 AddButton (name);
 }
 
 public void AddButton(string name){
 if (name == "cupcake") {
 
                 Item item = itemList [0];
                 GameObject newButton = buttonObjectPool.GetObject ();  // get object from pool
                 newButton.transform.SetParent (contentPanel);
                 SampleButton samplebutton = newButton.GetComponent<SampleButton> ();
                 samplebutton.Setup (item, this); // this refer to this scrolllist
         }
         if (name == "friedegg") {
 
                 Item item = itemList [1];
                 GameObject newButton = buttonObjectPool.GetObject ();  // get object from pool
                 newButton.transform.SetParent (contentPanel);
                 SampleButton samplebutton = newButton.GetComponent<SampleButton> ();
                     samplebutton.Setup (item, this); // this refer to this scrolllist
 
 
         }
 }
 
 private void RemoveButton(){
         while (contentPanel.childCount > 0) {
 
             GameObject toRemove = transform.GetChild (0).gameObject; // as long as there still has child game object there always be child zero, remove
             buttonObjectPool.ReturnObject(toRemove);
             Debug.Log ("What num" + toRemove);
         }
     }
 
 public void TryTransferItemToOtherShop (Item item){
 RemoveItem (item, this); // current
         RefreshDisplay();
 }
     private void RemoveItem( Item itemToRemove, ShopScrollList shopList){
         Debug.Log ("Shoplist777" + shopList.itemList.Count);
         Debug.Log("itemremove88" + itemToRemove.itemName);
         for (int i = shopList.itemList.Count -1; i >=0; i--) {
             if (shopList.itemList [i] == itemToRemove) {
                 shopList.itemList.RemoveAt (i);
                 Debug.Log ("remove list" + itemToRemove.itemName);
                 Debug.Log ("number" + i);
 
             }
 
         }
     }
 }


This SampleButton.cs is the prefab that is called from shopScrollList.cs

SampleButton.cs

 public Button button;
     public Text nameLabel;
     public Text priceLabel;
     public Image iconImage;
     // Use this for initialization
     private Item item;
     private ShopScrollList scrollList;
 
 public void Setup(Item currentItem, ShopScrollList currentShopList){
 
         item = currentItem;
         nameLabel.text = item.itemName;
         priceLabel.text = item.price;
         iconImage.sprite = item.icon;
 
         scrollList = currentShopList;
 
 }

I want to have more than one prefabs appear on the same Shop UI list once I swipe continuously with 3D objects.

Comment
Add comment
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

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

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

Related Questions

how can i do this, a rotating 3d object on canvas? 2 Answers

vertical layout problem using prefab buttons 1 Answer

Advice on how to reference a list in a scrollview with prefabs 0 Answers

Re-instantiated prefabs desist changes in text component 1 Answer

Select a prefab from shop to Player - 2D Game 0 Answers


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