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 psyhova · Aug 03, 2016 at 11:58 PM · raycastvariablehitinformation

How to save a variable of a raycast??

If I raycast an object and the hit info gives me the name of the object. Lets say "cube". How can I save this string??? saveName =hit.transform.name But If the raycast hits an other Object lets say Sphere the code above will be updated. And the saveName is named as sphere. But I want to save the string of the cube and if the raycast hits another obect I want to compare if(saveName !=hit.transform.name) then do.....

I can not use Tags vbecause Im checkingt the triangle index`s of an object. and therefore I must know when the Index is chancing.

Thanks for links and advices...

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by itsharshdeep · Aug 04, 2016 at 12:53 PM

Hi

I think you can do like all of the cubes should be on same layers lets say 'RayCast'. & other gameobjects will be on another later say 'IgnoreRaycast' now you will check before saving the name that the hitted object is on raycast layer or not.. if it is on 'Raycast' only then it will save name

Example: https://docs.unity3d.com/Manual/Layers.html

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 psyhova · Aug 04, 2016 at 02:13 PM 0
Share

Thanks for your response but I cannot use Layers. Because Im checking the triangle index of an object. So its not possible to layer each triangle of the object. The cube and sphere example would work with layers. I need to know when the raycast changes the index.

Is there no other way?

Cheers

avatar image itsharshdeep psyhova · Aug 04, 2016 at 03:02 PM 0
Share

mm... First of all next time you need to post this response as a comment on the respective answer ins$$anonymous$$d of the adding a new answer.. because this is response to any answer not a answer..

Secondly can you provide more depth detailed on your project .. like the provided answer is response to the given example. So please update the example. So that we can re-think.

Sorry for the little rude.. but when newbies come to you solve their problem they will feel little typical to collect the structured response.

Thanks

avatar image psyhova itsharshdeep · Aug 05, 2016 at 02:19 PM 0
Share

Thanks for your advice, I was not aware of this function to reply..

avatar image
0

Answer by NoseKills · Aug 04, 2016 at 03:46 PM

Your question is quite vague but from what i understand you could just store the name to a variable and compare it the next time you get a hit.

 private string lastHitObjectName;
 
 void OnCollisionEnter2D(Collision2D coll) {
       if (coll.gameObject.name == lastHitObjectName) {
        // you hit an object with the same name as last time
       }
       // store the objects name so we can compare 
      // it on the next hit
       lastHitObjectName = coll.gameObject.name;
 }
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 psyhova · Aug 05, 2016 at 02:30 PM

I better specify my problem.

I have a camera with a Raycast transDirection.fwd. and hits a sphere. (works only with a mesh collider attached to a primitive) And this raycast gives me a triangle index back. When I move the camera the Triangle index is changing, if the ray hits another Triangle of the mesh.

What I need, is to print out "The triangle Index has changed"

My problem is that, if I store like this: var saveTriIndex = Hit.triangleIndex; The variable itself changes too. If the raycast hits a new triangle. So I cannot compare, because the variable already has changed trough the update. So I need the old TriangleIndex. Something like deltaTriangleIndex.....

 function Update () {
 
 
 Debug.DrawRay(transform.position,transform.TransformDirection(0,0,1)*1000,Color.red);
 
  var hhh :RaycastHit;
 
 if (Physics.Raycast(transform.position,transform.TransformDirection(0,0,1),hhh,1000))
 
 
 {
 print ("TriIndex"+hhh.triangleIndex);
 
 //print(HOW TO PRINT TRIANGLE INDEX HAS CHANGED????????);
 }
 
 
 
 }
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

83 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Third person shooter need some help 0 Answers

Making a portal inspired game - Need help! 0 Answers

LineRenderer doesn't go to Hit.Point 1 Answer

Raycast Performance 3 Answers

Find Script and call function FROM hit.transform 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