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 NinjTsax · May 17, 2015 at 11:23 AM · touch controlsdestroy objectinput.touchdestroy-clonesgettouch

touch and destroy clone object with specific color

Hello all, i have big problem and i try to solve it 2 days.. try with timers different ways but nothing.. my brain stuck...

here is my code

 void FixedUpdate () {
         random = boxGenerator.randomColor;
     RaycastHit hit = new RaycastHit();
             for (int i = 0; i < Input.touchCount; ++i) {
                 if (Input.GetTouch(i).phase.Equals(TouchPhase.Ended)) {
                     // Construct a ray from the current touch coordinates
                     Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
                     if (Physics.Raycast(ray, out hit)) {
                         if(gameObject.GetComponentInChildren<Renderer>().material.color == colors[random])
                         {
                             Destroy (this.gameObject);
                             scoreScript.increaseScore(score);
                             Debug.Log("Pathsa " + gameObject.GetComponentInChildren<Renderer>().material.color + " enw " + colors[boxGenerator.randomColor]);
                             boxGenerator.randomGenerator();
                             Time.timeScale = 1;
                         }
                         else
                         {
                             scoreScript.gameOver();
                             Destroy (this.gameObject);
                             missionTextScript.gameOver();
                             gameOverMenuScript.gameOverEnabled = true;
                             Time.timeScale = 0;
                         }
                     }
                 }
             }
 }

my game generate a random color and you have to touch a box with the specific color.

when i touch the corect object the game show game over screen ! like i touch wrong object....

i saw that when i press 1 object all with same color destroyed so i think if something is wrong with instatiate and clones...

must to add the prefab and not the clone?

thanks

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 barbe63 · May 17, 2015 at 11:40 AM 1
Share

Some problem you have is you want to check if the object touched is a color box before doing anything. Right now you are not checking anything but the color of the material so basically your function is destroying everything you touch with a specified color.

avatar image $$anonymous$$ · May 17, 2015 at 11:56 AM 1
Share

First of all I second @barbe63's comment.

Secondly you might want to try a something simpler first. Start by just Debug.Logging the color of the objects that you touch. It is possible that there is a discrepancy between the materials color and the random color.

avatar image NinjTsax · May 17, 2015 at 01:12 PM 0
Share

thanks for your answers ! With debugging i found somthing really crazy.. i create new script to handle the touches and send request to destroy the object to tother script atatched to gameobject!

Thanks !!!!

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Difference between Destroy and Destroy immediate (In this case). 2 Answers

Count a touch in half of screen 2 Answers

How to make Touch Input act like GetAxis? 0 Answers

How can I destroy many instantiated objects on endless game 1 Answer

Input.GetTouch never getting TouchPhase.Ended on Android 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