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 /
  • Help Room /
avatar image
0
Question by DarkLiquid43 · Nov 06, 2015 at 07:43 PM · raycastenumdrag-and-dropc++search

How to use Raycast to scan everything under dragged 2d object to specify where it can be placed?

This may be hard to explain.
Im making a card game and i have the basics set up so far but i have an Enum set up to define card types.
enum Slots (Monster, Magic, Equip, blah blah). I was wondering how would I make the code to specify 1 card to be allowed to be dragged and dropped on top of another card else be put back where you got it from. So far all I have in concept thought is
RayCast (something something) {
If Draggable.Slot.EQUIP (is ontop of) Draggable.Slot.Monster {
do whatever the cards are supposed to do.
}
Else parentToReturnTo {
(I forgot what I had for the parent to return to but I hope you get the gist);
}
}

I need help filling in the blanks and i can post both of my scrips for better context of what im thinking of doing if you want but i don't have a clear way of executing it and google isnt helping me personally. i got most of my code from a good programmer youtuber and i used what he showed in his tutorial and ran with it and i hit a pretty big mental snag here.

I realise that i may be able to use the line

PlaceHolder[] zones = GameObject.FindObjectOfType();

and then search for all gameobject of the Slot.Monster for Slot.Equip to be dropped on top of...right?

or

EventSystem.current.RaycastAll( eventData )

this one is more specific to what is under the mouse so id think this one would work better for what im trying to do.

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
1

Answer by brazmogu · Nov 09, 2015 at 12:38 PM

I suggest you use BoxCast for that, as the documentation states that

A BoxCast is conceptually like dragging a box through the scene in a particular direction. Any object making contact with the box can be detected and reported.

Though BoxCast is 2D only. If You're going 3D, then you can raycast from all the borders of the card on the directoin of the screen(probably Vector3.forward, I think?) and check if any hit on a card below.

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 DarkLiquid43 · Nov 09, 2015 at 11:35 PM 0
Share

Otay, ill try that today or tomorrow sometime. id need to looks up more on box cast vs ray cast because i do plan on making it on a 3d plane but every prospective is going to be 2d set on a 3d board, cards are still 2d though.

So i guess Raycast like you said.
So in theory it would raycast from the borders of the card to scan for things under it (or if it hits anything in general) in the direction its mainly going to be moving, yes?

or would BoxCast work better in this instance?
Thank you for all your help in advance by the way.

avatar image
0

Answer by DarkLiquid43 · Nov 22, 2015 at 04:35 AM

After a good deal of research that comment didnt really help but it pointed me in a good direction. sorta. i need colliders and triggers from 2d colliders section in the engine. i found them and just need to watch a few more videos on how to use them correctly for what i need.
and a good bit of code. c:

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to change the enum value of an instance of a prefab being clicked 0 Answers

Dragging object, raycast blocked by object 0 Answers

Null Reference with ifstatements accessing enum types. 2 Answers

GraphicRaycaster.Raycast doesnt work properly while executing OnEndDrag(...) 1 Answer

Accesing enum type from another script 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