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 MaxJDET · Sep 09, 2017 at 07:51 AM · 2d gamebuilding2.5dsandbox

2D Building Script Help Needed

C# I am using 3d Cubes in this 2d sandbox game because 2d Quads didn't work.

 using System.Collections;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Inventory : MonoBehaviour {
     public Text InventoryText, SelectionText;
     int[] counts = new int[7];
     int selectedTile;
     string[] names = new string[] { "Dirt", "Turf", "Stone", "Iron", "Ramp", "Diamond", "Solid Fuel" };
     public GameObject[] tiles = new GameObject[7];
 
     void Update()
     {
         InventoryText.text = "Dirt: " + counts[0] + "Turf: " + counts[1] + "Stone: " + counts[2] + "Iron: " + counts[3] + "Ramps: " + counts[4] + "Diamond: " + counts[5] + "Solid Fuel: " + counts[6];
         if (selectedTile < 0)
         {
             selectedTile = counts.Length - 1;
         }
         if (selectedTile > counts.Length - 1)
         {
             selectedTile = 0;
         }
         if (Input.GetKeyDown(KeyCode.UpArrow))
         {
             selectedTile++;
         }
         if (Input.GetKeyDown(KeyCode.DownArrow))
         {
             selectedTile--;
         }
         SelectionText.text = names[selectedTile];
         if (Input.GetMouseButtonDown(1)){
 
             if (counts[selectedTile] > 0)
             {
                 Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                 Vector3 placepos = new Vector3(Mathf.Round(mousepos.x), Mathf.Round(mousepos.y), 0f);
 
                 if (Physics2D.OverlapCircleAll(placepos, 0.25f).Length == 0)
                 {
                     GameObject newTile = Instantiate(tiles[selectedTile], placepos, Quaternion.identity) as GameObject;
                     counts[selectedTile]--;
                 }
             }
         }
     }
     public void Add(int tileType, int count){
         counts[tileType] += count;
     }
 }
 

Thanks :)

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

74 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

Related Questions

Big problem with movements and animations 1 Answer

how to prevent clicking gameobjects behind NGUI panel 0 Answers

2D collider problems. The colliders seem "unstable". 3 Answers

I want to delete a Tile on Mouse Coordinates in a 2d game 0 Answers

Block Perspective in Top-Down 2D Games 2 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