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 cj12345 · Jan 15, 2014 at 04:48 PM · androidraycastbuttonfpstouchscreen

I am making android fps and my raycast shooting button don't work. What I should do?

I have android fps touch control and it works great. But fps shooter needs gun also. So I made I script for touchscreen raycast shooting. It shoots, but bad thing is everytime when I touch screen it shoots (example when I look around or move or just touch some random point on screen). And the button what I made for raycast shooting don't do anything, so when I press the button nothing happens. Yellow button is the raycast shooting button, red is sight for raycast shooting and fps moving and looking around are in right and left corners on photo. So can you awesome people help me? :)alt text

HERE IS MY CODE:

 var fireButton : GUITexture;
 var Effect : Transform;
 var TheDammage = 100;
 var sound : AudioClip;
 
 
 function Update(){
  
   for (var evt : Touch in Input.touches) {
  
   var HitTest1 = fireButton.HitTest(evt.position);
  
   if (evt.phase == TouchPhase.Began) { 
  
 if(HitTest1){
     audio.PlayOneShot(sound);
     audio.Play();
   }
   
   var hit : RaycastHit;
   var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
   
     if (Physics.Raycast (ray, hit, 100))
     {
             var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
             Destroy(particleClone.gameObject, 2);
             hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
             }
         }
     }
 }            
screenshot_2014-01-15-18-30-40.png (30.6 kB)
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
0
Best Answer

Answer by robertbu · Jan 15, 2014 at 04:53 PM

You are almost there. Your Raycast() code needs to be inside your if(HitTest1) condition. Your indentation here is a bit messed up, but if you move the '}' bracket on line 18 down to line 29, your code should work.

Comment
Add comment · Show 2 · 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 cj12345 · Jan 15, 2014 at 06:12 PM 0
Share

Sorry I am not good at coding.., could you copy and write fixed code in here? Because I dont understand all what you say (I'm not good at english). And say to your people that you have done amazing work and you have good customerservice!

avatar image cj12345 · Jan 16, 2014 at 04:49 PM 0
Share

Oh never $$anonymous$$d. I got it:)

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

18 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

Related Questions

[Android] Why does my enemy die no matter where I am in the 3D environment? 1 Answer

Problem with touch button (when moved) 2 Answers

Touch screen on Android to pause the game 1 Answer

i done this b4 but forgot :( touch screen 2 Answers

Fps Ammo pickup problem(programming noob) 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