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 xNiiCADEMUS · Jan 30, 2013 at 01:42 PM · vector3transform.positionphysics.raycast

Trying to click an object and have that object see what objects are near it and manipulate them based on certain rules

Trying to click an object then have that object look for objects near it and manipulate them. Pleae help, I've been working on this for a week!

 function Update (){
         
     var up = transform.TransformDirection(Vector3.up);
     var right = transform.TransformDirection(Vector3.right);
     var left = -transform.TransformDirection(Vector3.right);
     var down = -transform.TransformDirection(Vector3.up);
     var hit2 : RaycastHit;
     
         if ( Input.GetMouseButtonDown(0)){
         var hit : RaycastHit;
         var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             if (Physics.Raycast (ray, hit, 100.0)){
                 if (Physics.Raycast(transform.position,up,hit2,5) || Physics.Raycast(transform.position, down, hit2,5) || 
                      Physics.Raycast(transform.position,right,hit2,5) || Physics.Raycast(transform.position,left, hit2,5))
                      {
                      Debug.Log("go");
                      Debug.DrawRay(transform.position, up
 * 7,Color.white);
                     Debug.DrawRay(transform.position, down * 7,Color.white);
                     Debug.DrawRay(transform.position, right * 7,Color.white);
                     Debug.DrawRay(transform.position,
 -right * 7,Color.white);
                     if (hit2.collider.gameObject == this.collider.gameObject){
                     Destroy(hit2.collider.gameObject);
                     }
         }
         }
     }
     }
 

I have many plane objects. Think cards laying flat on a table with an orthographic camera facing down at them. (it's a 2d puzzle game) I want to click on one of the colored square plane objects and when I click on it, I want the object I click to send out a ray to each side to see what color the objects are that are directly next to it. Then I want to change the color of the objects next to the one I clicked based on a set of rules I will come up with. I've tried many many things over the past week. This is for android but right now I have a script that lets me click the object in the editor so I can use debug.ray to see if the rays are shooting and where to.
I also have seen rays shoot in the wrong direction. I havent been able to change it. It will shoot left and right of the object but not up and down. I shoots forward and back. Please help!

Comment
Add comment · Show 1
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 xNiiCADEMUS · Jan 30, 2013 at 12:26 PM 0
Share

As the code stands now, when you click an object it sends rays forward, backward, left, right on ALL objects not just the one clicked. Then ALL objects destroy.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get closest Vector3 position from a GameObject and two Transforms (and the line inbetween them) 2 Answers

Help with this script? Keeps moving my objects around in run-time? 0 Answers

smoothly change position of an Object 1 Answer

Script works with hard coded values but not variables 2 Answers

AddForce to a randomly selected GameObject with a rigidbody 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