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 JaredColl98 · Oct 25, 2012 at 12:50 AM · instantiateloopraygetmousebuttondown

Create objects in a selected area

I have written code for a loop to create objects in a select area based off mouse position A and Mouse position B. but the problem i have come across is that it only works is if point1 is to the right of and lower to point2, How can write this correctly?

var point1 : Vector3;

var point2 : Vector3;

var z : float;

var ray : Ray; //Camera.main.ScreenPointToRay(Input.mousePosition);

 if (Input.GetMouseButtonDown(0) && box2)
      { 
          point1= ray.origin + (ray.direction*distanc);
          point1.y =  hieghtFloor;
           point1.z = Mathf.RoundToInt(point1.z);
           z = point1.z;
           point1.x = Mathf.RoundToInt(point1.x);
           pointStr1 = point1.x+","+ point1.y+"1,"+point1.z;
           Debug.Log("Point "+pointStr1);
 
       }
       if (Input.GetMouseButtonUp(0)&& box2)
           {
               point2= ray.origin + (ray.direction*distanc);
               point2.y =  hieghtFloor;
               point2.z = Mathf.RoundToInt(point2.z); 
               point2.x = Mathf.RoundToInt(point2.x);     
               pointStr2 = point2.x+","+ point2.y+","+point2.z;
               var currentz : int = point2.z- point1.z;
               var currentx : int = point2.x-point1.x;
               var maxInt : int = currentz*currentx;
             
             if(maxInt > 0)
             {
                 for(var i = 0;i <= currentx; i++)
                 {
                     for(var t = 0 ;t <= currentz; t++)
                     {
                         if(!GameObject.Find(pointStr1) && !GameObject.Find(pointStr2))
                         {
                              currentObj=GameObject.Instantiate (startCube,point1, Quaternion.identity);
                              pointStr1 = point1.x+","+ point1.y+"1,"+point1.z;
                              currentObj.name = point1.x+","+ point1.y+"1,"+point1.z;;
                              
                         }
                         point1.z++;
                         pointStr1 = point1.x+","+ point1.y+"1,"+point1.z;
             
                     }
                     
                     point1.x++;
                     point1.z = z;
                     pointStr1 = point1.x+","+ point1.y+"1,"+point1.z;
                 }
             }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Memige · Oct 25, 2012 at 01:19 AM

After you get your second point, do a quick compare to see if the second one is to the top left of the first. if it is, you're good to go, if not, swap the values ie

 var temp : Vector3 = point1;
 point1 = point2;
 point2 = temp;

This should allow your existing code to work identically regardless what the orientation of the two mouse inputs are.

Comment
Add comment · Share
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
0

Answer by JaredColl98 · Oct 25, 2012 at 05:31 AM

No i cant get this to work

Comment
Add comment · Show 1 · Share
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 Memige · Oct 25, 2012 at 06:05 PM 0
Share

Ok, my answer was mostly algorithmic, so I'll have a look and see if I can get a practical fix working. To help me get started can you give me more details on how you implemented my suggestion, and what broke?

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

10 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

Related Questions

Mouse Over, Mouse Down, and Instantiate. 1 Answer

Problems with Custom Tool Tip Generation 1 Answer

Trying to not make an infinite loop 0 Answers

Instantiate color change loop 0 Answers

Passing variables to an instantiated object 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