Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 yashetv · Sep 04, 2018 at 04:28 PM · androidunity 2dfollowing

Following the newly created object

At the beginning I would like to apologize for my weak English


What's going on:

  • I'm making an Android app

  • I have a script "levelGenartor", it's obvious what is doing

  • Each of prefabs level has "childs"

  • The purple mark (empty Game.Object) is named and tagged as a "door", and it's generally a transition between levels

  • That's how it looks like:

screen1 alt text


The player has to move right or left depending where is a door. When someone touch the screen the "player" jumps to the next level. At this point, the next transition (door) have to be found - based on their position the vector of the movement will change.


I am totally new in unity (about 2 weeks) and I think that I don't have general knowledge about methods, functions etc. I tried many times with this but unfortunately with poor results. Any ideas ?

2.png (27.4 kB)
3.png (6.4 kB)
Comment
Add comment · Show 5
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 misher · Sep 04, 2018 at 04:47 PM 0
Share

Post your code, what have you done so far?

avatar image FernandoHC · Sep 04, 2018 at 05:08 PM 0
Share

If you have to access the gameObject/script for the closest door to the player, I'd suggest having a list of references of all the doors sorted by distance to the player.
For example, an instance of List<DoorScript> doorsList where all doors are referenced ( can be done via inspector or at runtime if your code generates them dynamically).
To access the closest one i'd do something like doorsList[0] and once the door has been used and the player moves to the next one, you can either control by having an index and do doorsList[currentDoor] or remove onces used by doing doorsList.RemoveAt(0) and doorsList[0];

avatar image yashetv · Sep 05, 2018 at 11:30 AM 0
Share

@FernandoHC It's a good idea, I' ll try this later and I will say if it worked. In other words, "if I can do it at all." (ahh don't even know what I'm writing)

@misher // This is my "levelGenerator" code

     private something rooms; //Reference to the GameObject Array (public GameObject[] platforms)
     private int rand;
     public float y_axis = 0.8f;
     private int platformLimit = 0;
     private Transform door;
 
     void Start()
     {
         rooms = GameObject.FindGameObjectWithTag("rooms").GetComponent<something>();      
     }
 
     void Update()
     { 
         if(platformLimit < 10){
             rand = Random.Range(0, rooms.platforms.Length);
             Instantiate(rooms.platforms[rand], new Vector3(-12.2f, y_axis, 0), rooms.platforms[rand].transform.rotation);
 
             y_axis += 1.2f;
             platformLimit++; 
         }    
     }

Each of doors (dynamically created) has Tag: rooms attached to them

avatar image misher · Sep 05, 2018 at 11:47 AM 0
Share

Please describe better the gameplay and question. I assume this: 1. You start with only player object, user can move it left or right and jump. 2. On Scene loaded, your level generator starts to generate "floors" (2 sections with a hole in between them at random position), 3. Generator only make several floors, then, only when player progress to the next floor, generator will add one more floor at the top (and destroy the bottom one) 4. When player jumps into the hole between 2 sections of the floor above, this should trigger progressing to the next floor (how exactly you have implemented that)

avatar image yashetv · Sep 05, 2018 at 12:10 PM 0
Share

Yes exactly ! Everything as you said in addition to point 3. $$anonymous$$y script generated the floors infinitely and I had to limit it to 10 (btw. I want to do it as you said. In the sense that the camera moves higher, the floors at the top will be added and the bottom ones will be removed)

$$anonymous$$y problem is how to find a newly created object -> read it's position -> and on this basis, deter$$anonymous$$e the player direction vector

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by misher · Sep 05, 2018 at 01:25 PM

Moving camera infinitely is not a good idea, better to shift all floors down. When a player jumps into the hole between 2 segments of the floor it can hit a trigger, add collider to your "purple mark object" and flag it as trigger. Then in your Player script you can use this:

 void OnTriggerEnter(Collider other)
 {
     Debug.Log(other.transform.position); // position of your trigger (floor transition market)
     LevelManager.TransitionToNextFloor(); // proceed to nex floor (your custom logic)
 }

Make sure to add rigidbody to your player object

Comment
Add comment · Show 3 · 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 yashetv · Sep 06, 2018 at 06:26 AM 0
Share

Okay, I get it how can it work, but..

  void OnTriggerEnter(Collider other)
  {
      Debug.Log(other.transform.position); // position of your trigger (floor transition market)
      // Level$$anonymous$$anager.TransitionToNextFloor(); // proceed to nex floor (your custom logic)
  }

When my "player" touches the door with: BoxColider2D and isTrigger = true: Nothing is shown in the console log. Only when Collision is detect position shows correct.

avatar image misher yashetv · Sep 06, 2018 at 06:39 AM 0
Share

https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerEnter.html Do you have rigidbody component on your player object?

avatar image yashetv misher · Sep 06, 2018 at 02:20 PM 0
Share

Yes, I have ! When isTrigger == false, then position is detected but also player doesn't move forward

avatar image
0

Answer by telecaster · Sep 04, 2018 at 10:02 PM

Is there any reason why the generated doors could not be a prefab that has a script object on it? The script would simply at instantiation find any game object you wish to find and assign it to the script. You then can do whatever you want with either object in that script. Find in unity can be found here: https://docs.unity3d.com/ScriptReference/GameObject.Find.html

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 yashetv · Sep 05, 2018 at 11:39 AM 0
Share

I don't really understand. Each of "door" would have a script Component (who does what?) GameObject.Find don't help a lot, because levels are created dynamically and has the same name :/

If I'm wrong - really sorry, but I don't get it :c

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

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

After i added proguard codes, I cannot connect to Google Play Service 0 Answers

Handling Multiple Aspect Ratios in Unity2D? 0 Answers

Transparency problem On phone 0 Answers

[5.4 - Unity2D - Android] UI Button Requires Child Text? 0 Answers

Tilemap Collider not working after build 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