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
1
Question by Althaen · Jun 18, 2013 at 03:30 AM · c#raycastnguics

NGUI and raycast hit point

I'm trying to create a script to move my character to a point on the terrain that works with NGUI because currently I am using a script along with NGUI and it is causing me issues.

     void rayCastClick()
     {
         if (Input.GetButtonDown("Mouse0"))
         {
             
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
                 
             if(Physics.Raycast(ray, out hit, 100))
             {
             
                 if(hit.collider.gameObject.tag == "Terrain")
                 {
                     //Take hit point and move to hit position on terrain
                 }
             }
         }
     }
 }

Can anyone give me an example of how I would do this using NGUI's event system? I'm not sure how to do it.

Comment
Add comment · Show 2
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 iwaldrop · Jun 18, 2013 at 04:27 AM 0
Share

Could you clarify how NGUI plays into moving your character? NGUI is for buttons, lists, etc, but doesn't really do anything beyond that (i.e., its not for moving scene objects around).

Are you wondering how to get a button to tell something to 'DO YOUR THING'?

avatar image Althaen · Jun 18, 2013 at 04:42 AM 0
Share

NGUI uses raycasts apparently so me making my own raycasts messes with NGUIs ones. I just don't understand how to use NGUI to do the same thing.

I want the point on screen I click to fire a ray that checks whether the terrain is hit and moves the player towards the vector of where the ray intersects the terrain.

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by whydoidoit · Jun 18, 2013 at 06:00 AM

NGUI uses raycasts but your raycasts are not affecting it - it doesn't work like that. I would leave it alone as @iwaldrop says because your UI should be on a different layer to everything else (and your UI should normally be positioned away from your scene).

If you do want to access the last thing hit by NGUI it's in:

       UICamera.lastHit
Comment
Add comment · Show 3 · 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 Althaen · Jun 18, 2013 at 06:05 AM 0
Share

$$anonymous$$y raycasts go through buttons and hit the terrain, which I don't want.

avatar image whydoidoit · Jun 18, 2013 at 06:08 AM 4
Share

Technically that isn't happening, but I understand what you mean - visually it appears to happen. I would not send your raycast if UICamera.hoveredObject != null.

avatar image Bunny83 · Jun 18, 2013 at 06:18 AM 0
Share

I guess this comment is what he needs :)

avatar image
0

Answer by Andres-Fernandez · Feb 20, 2014 at 07:51 AM

You have to attach the UICamera script to your main camera object (the one that shows the terrain)and set the Event type to UI/World (I can't remember which one, but I guess it is World). That way, objects shown by that camera will also generate the NGUI events.

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 CoderPro · Aug 21, 2014 at 03:22 PM

You should set for NGUI's camera is MainCamera tag.

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 chaurasiyapawan · Nov 13, 2014 at 07:46 AM

May be you can use this

static bool UICamera.IsPressed ( GameObject go)

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

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

20 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Raycast - arrow stopped by walls (layer) but not by units (layer) 1 Answer

2 raycasts on the fpwalker/camera 1 Answer

how do i make my objects not spawn on already spawned objects 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