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 Amberlewis012 · Aug 17, 2020 at 12:33 PM · triggerheightstack

How to make the game win once the correct height is reached

Hello, gonna try to keep this short and concise like the rule says. Sorry if this is weird or bad or something. I'm trying to make a game thing kinda like those stacking games or tetris but 3D. You control an object in the air, and when you press a certain button, it drops. If it lands on a target platform thing, you get a point and it spawns a new object, and you basically repeat that process until the blocks stack to reach a certain height, and you win the level. If it misses that target, then game over and reload scene.


Anyways, problem with that last part. How do I make it so when they stack on each other and reach that height, it activates a UI or something like that, and when you release the object it doesn't accidentally activate it when it goes through it? Once again, sorry if this is a really dumb or easy question, but I am just a newbie. Thanks in advance!

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

2 Replies

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

Answer by Riki9811 · Aug 17, 2020 at 02:07 PM

I think there are 2 ways of doing it.

First way:
Whenever an object falls and hits your platform use:

 this.GetComponent<Renderer>().bounds.max.y

This will return the y of highest point of the object, and you can check if it is above the value you want



Second method:
Set up a trigger collider at the hight that you want
Give this new gameObject a tag, let's say "Finish line".
Then in the script to the objects you spawn in write:

 void OnTriggerEnter(Collider other) {
     if (other.gameObject.CompareTag("Finish line"))
     {
         //Do something
     }
 }

Then set the "Finish line" to be disabled by default.
Every time the falling object lands enable the "Finish line" gameObject. Doing so will also trigger every OnTriggerEnter() event on all the objects that go through it.
If you haven't reached the height you wanted then simply disable the "Finish line" again before spawning the new object.

I think the firs method is cleaner and mush simpler, but I'm not sure if it can give you some problems with reading the highest point of some 'oddly' shaped 3D models.

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 Amberlewis012 · Aug 17, 2020 at 02:48 PM 0
Share

I tried using your first method and wooo it works ($$anonymous$$aybe because the shape of my object is slightly strange so it's sometimes a bit off but it works 99% fine normally). Thanks for helping!

avatar image
1

Answer by JackhammerGaming · Aug 17, 2020 at 02:10 PM

@Amberlewis012 i am gonna try my best from what i understood from what you need try something like

 GameObject last_instantiated_object;
 public float win_pos; // set this equal to the y co-ordinate of the height after which level is won
 
 public void OnButtonClick(){
 last_instantiated_object = Instantiate(stack ,transform.position); // stack is the object which is getting dropped i don't know the name of your variables in your script
 
 if (last_instantiated_object.transform.position.y >= win_pos){
 ui.SetActive(true); // ui is a variable name for win screen gameobject
 }
 }

last_instantiated_object is the variable name for the object you last instantiated or simply the object which is being dropped. it will be better if you share your script too

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 Amberlewis012 · Aug 17, 2020 at 02:50 PM 0
Share

I did what the other guy wrote already and it works so this isn't a problem anymore. Thanks for helping though, seriously!

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

157 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 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 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 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 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 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 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 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 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

How to measure the height of 3D objects. 3 Answers

Can't click gameobject when over another trigger? 1 Answer

OnTriggerStay called once option? 1 Answer

linking particlesystem to cube,conecting particlesystem to cube 0 Answers

Trigger animation, play once & disappear 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