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 /
avatar image
0
Question by soeiromass · Jun 01, 2016 at 07:23 AM · c#unity 5gameobjectraycasting

Unity - Remove GameObject

I have been developing a game in which we need to be able to select a GameObject (ingredient) and deselect it, and that by selecting that GameObject it adds a +1 to the counter. My objective is to use the raycast, within the GameObject "crossair", to select an ingredient and erase it from the scene.

I'm able to do that but only with the wrong ingredients (the ones that the player should not select). I don't understand why it doesn't work with the right ones.

Hope you can help.

My Screan

My Script in Aim: AimManager.cs

 using UnityEngine;
 using System.Collections;
 
 public class AimManager : MonoBehaviour {
 
     float TimeInterval = 8f;
     float time = 0;
     public UI_cozinha uiCozinha;
     public AimDrag aimDrag;
     public GameObject MainAim, FirstLogin, SecondLogin, ThirdLogin, FourthLogin, CheckLogin, GreenAim;
     public RaycastHit hit;
 
 
     // Use this for initialization
     void Start () {
        
     }
     
     // Update is called once per frame
     void Update () {        
 
         if (Physics.Raycast(transform.position, transform.forward, out hit))
         {
             if (time >= (TimeInterval / 8) && ( ( hit.transform.tag == "ButtonE") || (hit.transform.tag == "ButtonM") || (hit.transform.tag == "ButtonH") ) )
             {
                 MainAim.SetActive(true);
             }
             if (time >= ((TimeInterval / 8) * 2) && ((hit.transform.tag == "ButtonE") || (hit.transform.tag == "ButtonM") || (hit.transform.tag == "ButtonH")))
             {
                 FirstLogin.SetActive(true);
                 MainAim.SetActive(false);
             }
             if (time >= ((TimeInterval / 8) * 3) && ((hit.transform.tag == "ButtonE") || (hit.transform.tag == "ButtonM") || (hit.transform.tag == "ButtonH")))
             {
                 SecondLogin.SetActive(true);
                 FirstLogin.SetActive(false);
             }
             if (time >= ((TimeInterval / 8) * 4) && ((hit.transform.tag == "ButtonE") || (hit.transform.tag == "ButtonM") || (hit.transform.tag == "ButtonH")))
             {
                 ThirdLogin.SetActive(true);
                 SecondLogin.SetActive(false);
             }
             if (time >= ((TimeInterval / 8) * 5) && ((hit.transform.tag == "ButtonE") || (hit.transform.tag == "ButtonM") || (hit.transform.tag == "ButtonH")))
             {
                 FourthLogin.SetActive(true);
                 ThirdLogin.SetActive(false);
             }
             if (time >= ((TimeInterval / 8) * 6) && ((hit.transform.tag == "ButtonE") || (hit.transform.tag == "ButtonM") || (hit.transform.tag == "ButtonH")))
             {
                 CheckLogin.SetActive(true);
                 FourthLogin.SetActive(false);
             }
             if (time >= ((TimeInterval / 8) * 7) && ((hit.transform.tag == "ButtonE") || (hit.transform.tag == "ButtonM") || (hit.transform.tag == "ButtonH")))
             {
                 GreenAim.SetActive(true);
                 CheckLogin.SetActive(false);
             }
             if (time >= ((TimeInterval / 8) * 8) && ((hit.transform.tag == "ButtonE") || (hit.transform.tag == "ButtonM") || (hit.transform.tag == "ButtonH")))
             {
                 MainAim.SetActive(true);
                 GreenAim.SetActive(false);
             }
 
             if (time >= TimeInterval)
             {
                 if((hit.transform.tag == "ButtonE"))
                 {
                     uiCozinha.setDiff(5);
                 }if((hit.transform.tag == "ButtonM"))
                 {
                     uiCozinha.setDiff(7);
                 }
                 if ((hit.transform.tag == "ButtonH"))
                 {
                     uiCozinha.setDiff(10);
                 }
 
                 aimDrag.getReady(true);
 
                 time = 0;
             }
             else
             {
                 time += Time.deltaTime;
             }
         }
     
     }  
     
 }

My Script in Aim: AimDrag.cs

 using UnityEngine;
 using System.Collections;
 
 public class AimDrag : MonoBehaviour {
 
     public int erros, certos, totalDeErros, i;
     float TimeInterval = 8f;
     float time = 0;
     
     public bool StartNextOfMenu;
 
     public RaycastHit hit;
 
     public GameObject easy, medium;
 
     public GameObject farinha, fermento, ovos, leite, acucar;
 
     public GameObject agua, natas;
 
     public GameObject manteiga, oleo, bolachas;
 
     public GameObject[] ArrayEasy = new GameObject[5];
 
     public GameObject[] ArrayMedium = new GameObject[2];
 
     public GameObject[] ArrayDificult = new GameObject[3];
 
     public GameObject[] Nome = new GameObject[15]; // so ta a guardar na primeira posição
 
     
 
 
     // Use this for initialization
     void Start () {
         
 
     }
     
     // Update is called once per frame
     void Update () {
         if (StartNextOfMenu)
         {
 
             Debug.Log(certos);
             Debug.Log(erros);
 
             if ( Physics.Raycast(transform.position, transform.forward, out hit) )
             {
                 if (!easy.activeInHierarchy) // então esta no modo facil
                 {                    
                     for (i = 0; hit.transform.tag == "ComidasCertas" && time >= TimeInterval; i++) // Array.length
                     {
                         Nome[i] = hit.transform.gameObject;
 
                         if (Nome[i] == farinha || Nome[i] == fermento || Nome[i] == ovos || Nome[i] == leite || Nome[i] == acucar)
                         {
                             certos++;
                             
                             if(Nome[i] == farinha)
                             {
                                 print("nice!");
                                 farinha.SetActive(false);
                             }
                             if(Nome[i] == fermento)
                             {
                                 print("nice1!");
                                 fermento.SetActive(false);
                             }
                             if(Nome[i] == ovos)
                             {
                                 print("nice2!");
                                 ovos.SetActive(false);
                             }
                             if(Nome[i] == leite)
                             {
                                 print("nice2!");
                                 leite.SetActive(false);
                             }
                             if(Nome[i] == acucar)
                             {
                                 print("nice3!");
                                 acucar.SetActive(false);
                             }
                         }
                         else
                         {
                             print("teste de erros!");
                             erros++;
                         }
 
                         time = 0;
                         
                     }
                 }
 
                 if (!medium.activeInHierarchy) // então esta no modo medio
                 {
                     for (i = 0; hit.transform.tag == "ComidasCertas" && time >= TimeInterval; i++)
                     {
                         Nome[i] = hit.transform.gameObject;
 
                         if (Nome[i] == agua || Nome[i] == natas)
                         {
                             print("nice! m");
                             certos++;
 
                             if(Nome[i] == agua)
                             {
                                 print("nice1! m1");
                                 agua.SetActive(false);
                             }
                             if(Nome[i] == natas)
                             {
                                 print("nice1! m2");
                                 natas.SetActive(false);
                             }
 
                         }
                         else
                         {
                             print("teste erros 2!");
                             erros++;
                         }
                         time = 0;
                         
                     }
 
                 }
 
                 if (medium.activeInHierarchy && easy.activeInHierarchy) // esta no modo dificil
                 {
                     for (i = 0; hit.transform.tag == "ComidasCertas" && time >= TimeInterval; i++)
                     {
                         Nome[i] = hit.transform.gameObject;
 
                         if (Nome[i] == manteiga || Nome[i] == oleo || Nome[i] == bolachas)
                         {
                             print("nice1! d");
                             certos++;
                             
                             if(Nome[i] == manteiga)
                             {
                                 print("nice1! d1");
                                 manteiga.SetActive(false);
                             }
                             if(Nome[i] == oleo)
                             {
                                 print("nice1! d2");
                                 oleo.SetActive(false);
                             }
                             if(Nome[i] == ArrayEasy[2])
                             {
                                 print("nice1! d3");
                                 bolachas.SetActive(false);
                             }
                         }
                         else
                         {
                             print("teste erros 3");
                             erros++;
                         }
 
                         time = 0;
                         
                     }
                 }
 
 
 
                 if (hit.transform.tag == "ComidasEnradas" && time >= TimeInterval)
                 {
                     Nome[14] = hit.transform.gameObject;
                     erros++;
                     Nome[14].SetActive(false);
                     time = 0;
                 }
                 if (hit.transform.tag == "ComidasCertas" && time >= TimeInterval)
                 {
                     Nome[14] = hit.transform.gameObject;
                     erros++;
                     Nome[14].SetActive(false);
                     time = 0;
                 }
                 else
                 {
                     time += Time.deltaTime;
                 }
 
                 totalDeErros = certos - i + erros;
 
             }
         }
     }
 
     public bool getReady(bool confirmation)
     {
         if (confirmation)
         {
             return StartNextOfMenu = true;
         }
         else
         {
             return StartNextOfMenu = false;
         }
     }
 
 }


ee4678f93944195857f94d384febce33.png (308.4 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

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

Calling an Audio Source on one game object from a script on another game object..? 1 Answer

transform.SetParent(null); Not Working 1 Answer

How to destroy a particular clone on touch/mouse? 1 Answer

Multiple Cars not working 1 Answer

How to make a Interactive Computer Screen in Unity 5.5? 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