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 8r3nd4n · Nov 22, 2011 at 06:08 AM · raycasthitcomparetag

Raycast only working once

I have a scene where I have several different shapes. Attached to an object is a script containing the raycast stuff. When the ray intersects an object of a certain shape, I want it do show the shape that it has intersected.

For some reason, It will work the first time but as soon as I move off a shape, the raycast seems to do nothing and it wont recognize that its hit again the second time. It has me stumped cause I have used raycasts before and not run into this problem. It appears that it only runs the update once rather than continuously.

Help greatly appreciated

 using UnityEngine;
 using System.Collections;

 public class RaycastTriangle : MonoBehaviour {
 
 
 // Use this for initialization
 void Start () {
 
 }
 
 void Update() {
 RaycastHit hit;    
     Vector3 up = transform.TransformDirection(Vector3.up);
     if (Physics.Raycast(transform.position, up, out hit))
     {
         if (hit.collider.gameObject.CompareTag("Triangle"))
         {
             print("Triangle");
         }
         
         else if (hit.collider.gameObject.CompareTag("Circle"))
         {
             print("Square");
         }
         
         else if (hit.collider.gameObject.CompareTag("Circle"))
         {
             print("Circle");
         }
         
         else
         {
             print("No Shape");
         }
     }
     Debug.DrawRay(transform.position, up, Color.green);
     
 }

}

Comment
Add comment · Show 3
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 kevork · Nov 22, 2011 at 08:05 AM 0
Share

Is the object that this script attached to moving or rotating at all?

avatar image 8r3nd4n · Nov 22, 2011 at 08:32 AM 0
Share

The script is attached to an empty game object that is parented to a cube that moves around. each side of the cube has a raycast so that whenever it moves, it can pick up objects no matter what side of the cube they are on

avatar image chelnok · Jan 24, 2015 at 07:26 PM 0
Share

I just got email notice: "8r3nd4n has accepted an answer by 8r3nd4n for Raycast only working once"

Lets see.. You had a question, and you answered it by yourself after two days, with two identical answers. It took over three years to make up your $$anonymous$$d, which one is acceptable :)

2 Replies

· Add your reply
  • Sort: 
avatar image
9
Best Answer

Answer by 8r3nd4n · Nov 24, 2011 at 08:46 AM

Damn it I was pulling my hair out for so long and as usual the answer is so simple I can only laugh at my stupidity.

I was always checking the console for the hit detection but had the 'collapse' button toggled so it would only show it the first time.

ha ha ha

Comment
Add comment · Show 7 · 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 DavidErosa · Dec 14, 2012 at 08:56 PM 1
Share

Dude, you saved my $$anonymous$$d! xDDD I was having the same issue... Thanks! :D

avatar image Rixterz · Aug 28, 2013 at 12:23 PM 1
Share

I had this problem before and forgot all about it; now I have fallen for it again! Thanks 8r3nd4n!

avatar image chelnok · Aug 28, 2013 at 03:15 PM 1
Share

you're not the only one ..probably happened all of us at least ones :)

avatar image Roidz99 · May 26, 2014 at 01:34 PM 1
Share

hahaha , just logging in to say that i had the same 'bug'. rofl.

thanks for saving time !

avatar image vivek@xenium · Jan 23, 2015 at 08:48 AM 1
Share

You saved my time ...sometimes happens with programmers ...... : )

Show more comments
avatar image
1

Answer by 8r3nd4n · Nov 24, 2011 at 08:46 AM

Damn it I was pulling my hair out for so long and as usual the answer is so simple I can only laugh at my stupidity.

I was always checking the console for the hit detection but had the 'collapse' button toggled so it would only show it the first time.

ha ha ha

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

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

How to hit two objects with only one shot (raycast) 0 Answers

Need help with Third person shooter 0 Answers

Ray from enemy to player is always a bit off (Image) 1 Answer

RaycastHit.distance 1 Answer

how to get info on what raycast hitted 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