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 pravin gate · Mar 23, 2011 at 11:21 AM · gameobjectraycastdetection

Checking detection of gameobject correction

hii, i'm trying to develop one script for detection of cubes.

Below is that script.

script.js

function OnMouseDown () { Debug.Log("clicked"); CheckCubes(); }

function CheckCubes() { var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); var mousehit : RaycastHit;
if (Physics.Raycast (ray, mousehit) && (mousehit.collider.tag == "OLD_TRY")) { mousehit.transform.gameObject.active = false; } }

This script uses raycast concept, and if we click on gameobject ,gameobject disappears.

Now i just need to check that if all gameobjects are hitted(clicked), goes to next scene.

So anybody is having any idea or script, what should i can use to check all gameobjects are hitted?

Thanks,

Any suggestions will be helpful.

Comment
Add comment · Show 1
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 pravin gate · Mar 23, 2011 at 11:56 AM 0
Share

$$anonymous$$ore information regarding this:

I have taken n cubes , 1)First created a prefab,

2)then addes a custom tag and added it to prefab.

3)Then created this script and attached to this prefab

4)Then added all n cubes to that prefab.

4)so all cubes will takes properties of prefab.

Hope so it will be helpful.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Mar 23, 2011 at 11:53 AM

Just a little hint: OnMouseDown is not called just when you press the mouse button. It's called when you click on the collider of a GameObject. It's called just on that GameObject so you don't need to raycast. The OnMouseDown event is created by Unity and already uses a raycast internally to find the hitted GO.

That would do the same if every of your GameObjects that should be hitted have this script attached.

function OnMouseDown ()
{
    Debug.Log("clicked");
    gameObject.active = false;
}

In your case it would be the simplest thing to check right after you clicked on a GameObject. Just search for all gameobjects that have this script attached (name: script.js)

function OnMouseDown () { Debug.Log("clicked"); gameObject.active = false;

 // check if all objects are disabled
 var allObjects : script[] = Object.FindObjectsOfType(script) as script[];
 var allDeactivated = true;
 for (var current : script in allObjects)
 {
     if (current.gameObject.active)
         allDeactivated = false;
 }
 if (allDeactivated)
 {
     // here we know all are disabled, do what you want
     // eg. Application.LoadLevel("NextLevelName");
 }

}

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 pravin gate · Mar 23, 2011 at 12:46 PM 0
Share

hey i'm getting one problem, still not able to go to next level after last click on gameobject. First i was created a script wit name "script.js" function On$$anonymous$$ouseDown () { Debug.Log("clicked"); gameObject.active = false; } ////////////////////////////////////////

and attached that script to all n cubes

/////////////////////////////////////// and then created ur script for checking disability of objects. Is there any mistake happened by me? so why it didnt working?

avatar image
0

Answer by efge · Mar 23, 2011 at 12:02 PM

I thought this question was already answered here?!


You should set cubeCount to a valid number in the Inspector or by counting all GameObjects with tag = "ClickObjects".

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 pravin gate · Mar 23, 2011 at 12:25 PM 0
Share

yes sir, i was tried on that way also, but alerady as we have discussed , it is not checking all the cases.(Any sequence of clicking of cube ).

avatar image pravin gate · Mar 23, 2011 at 12:56 PM 0
Share

ok , just tel me for confirmation, i was changing the cubecount values of prefab and also, all cubes. is it rit way?

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

No one has followed this question yet.

Related Questions

Help with LineRenderer 1 Answer

How to get info of object within certain range?(Javascript) 1 Answer

Getting GameObject from a grid (array) using raycasters 0 Answers

How to detect if a raycast ray stop hitting an object 1 Answer

How to make a Ray class? 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