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 3 · Mar 24, 2013 at 05:01 AM · iosraycastmobiletagname

Why isn't hit.transform.name with ray working?

so the

 if(hit.transform.name == "Cancel upgrade"){

part of this script isn't working, even though everything else is. So once I touch "greatballupgrade" all these new things come up, and even though it registers me clicking the "Cancel upgrade" gameobject, it doesn't do anything.

Any help would be appreciated, I'm stumped. Here is the script:

   private var hit : RaycastHit;
     private var ray : Ray;//ray we create when we touch the screen
     var clone1 : SpawnBall1;
     var boughttext : GameObject;
     var buysell : GameObject;
     var behindobjects : GameObject;
     var buy : GameObject;
     var cancel : GameObject;
     var goldballupgrade1 : GameObject;
     //play boughtext animation and sound when item is bought.
     var target1 : ballmade;
       function FixedUpdate () {
         if(iPhoneInput.touchCount == 1) {
             ray = Camera.main.ScreenPointToRay(iPhoneInput.touches[0].position);
             Debug.DrawLine(ray.origin,ray.direction * 10);
             if(Physics.Raycast(ray.origin, ray.direction * 10,hit)){
      Debug.Log(hit.transform.name);//Object you touched
                              //target1 = GameObject.Find("Ball Made").GetComponent(ballmade);
                              //clone1 = GameObject.Find("Cylinder Spawn 3").GetComponent(SpawnBall1);
                                              }
                                              if(hit.transform.name == "Menureturn"){
                                 Application.LoadLevel("LoadMenu");
             }
     
                          if(hit.transform.name == "greatball Upgrade"){
                          buysell.gameObject.active = true;
                          goldballupgrade1.gameObject.active = true;
                          behindobjects.gameObject.active = false;
     if(hit.transform.name == "Cancel upgrade"){
     buysell.gameObject.active = false;
     goldballupgrade1.gameObject.active = false;
                          behindobjects.gameObject.active = true;
     }
             }
                                  if(hit.transform.name == "goodball Upgrade"){
                                  buysell.gameObject.active = true;
             }
     } 
     }
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

1 Reply

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

Answer by robertbu · Mar 24, 2013 at 05:28 AM

If you format your code, it is clear why you are having the issue. The "Cancel upgrade" is inside the "greatball Upgrade" 'if' statement:

Here is that section formatted:

  if(hit.transform.name == "greatball Upgrade"){
     buysell.gameObject.active = true;
     goldballupgrade1.gameObject.active = true;
     behindobjects.gameObject.active = false;
     if(hit.transform.name == "Cancel upgrade"){
         buysell.gameObject.active = false;
         goldballupgrade1.gameObject.active = false;
         behindobjects.gameObject.active = true;
     }
 }

There is no way that hit.transform.name == "greatball Upgrade" and hit.transform.name == "Cancel upgrade" at the same time.

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 3 · Mar 24, 2013 at 05:58 AM 0
Share

Hey, didn't you answer my last question too? Anyways, I figured it out $$anonymous$$utes before I checked this again, but thanks for helping again.

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

10 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

Related Questions

How to pick up object on touch? 1 Answer

Raycast detection / lag issue 0 Answers

Run Unity in background on mobile platform 1 Answer

testing on an android device 0 Answers

Why did my render time increase after lowering the vertex count? 2 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