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 gregoriuseggi · Jun 22, 2020 at 03:56 PM · next level

i have an issue about getting to next level,i have a question about getting to new level

so i want my player sprite getting to next level by avoiding 5 colliders. so how i code it? im new here, pls help me :(

heres my code

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class player : MonoBehaviour { public float moveSpeed = 600f;

 float movement = 0f;

 // Update is called once per frame
 void Update()
 {
    movement = Input.GetAxisRaw("Horizontal");
     
 }

 private void FixedUpdate()
 {
     transform.RotateAround(Vector3.zero, Vector3.forward, movement * Time.fixedDeltaTime * -moveSpeed); // untuk membuat hexagon mengerucut seiring berjalannya waktu
 }


 private void OnTriggerEnter2D(Collider2D collision)
 {
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
 }
   


},so i have this player sprite, i want to make this player survive the collider 5 time so it can continue to next level(new scene) heres the code

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class player : MonoBehaviour { public float moveSpeed = 600f;

 float movement = 0f;

 // Update is called once per frame
 void Update()
 {
    movement = Input.GetAxisRaw("Horizontal");
     
 }

 private void FixedUpdate()
 {
     transform.RotateAround(Vector3.zero, Vector3.forward, movement * Time.fixedDeltaTime * -moveSpeed); // untuk membuat hexagon mengerucut seiring berjalannya waktu
 }


 private void OnTriggerEnter2D(Collider2D collision)
 {
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
 }
   


}

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
0
Best Answer

Answer by MiB775 · Jun 22, 2020 at 08:47 PM

What do you mean by "avoiding 5 colliders"? Do they move towards the player? Let's assume you can check if the player avoided the collider with function "bool avoided()". What you do is:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

 public class player : MonoBehaviour
 {
    int collidersAvoided = 0;
    
    void Update()
    {
        if(avoided())
          collidersAvoided++;
    }
 
    private void OnTriggerEnter2D(Collider2D collision)
   {
      SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
 
     // If you just want to reset the score to zero, use:
     // collidersAvoided = 0;
     // It's faster than loading an entire scene
   }

}

But then, I don't know what do you mean by "avoiding colliders", so I don't know how to check it.

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 gregoriuseggi · Jun 23, 2020 at 05:08 AM 0
Share

there will be lots of hexagons which works as the obstacle of this game, so the player should avoid the hexagon in order to survive the game. if the player collides with the hexagon, the game resets. so the hexagon is the collider.

can u help me more?

here is the link to the screenshot of my game, because i have an error while uploading the picture here

https://drive.google.com/file/d/1$$anonymous$$e4ZlY2$$anonymous$$_WqR$$anonymous$$USKh7x1pj_83drAe4Qu/view?usp=sharing

avatar image
0

Answer by haizathaneefa · Jun 23, 2020 at 06:22 AM

have a script up for your colliders and have OnTriggerEnter function in it that checks if the ball is colliding with the colliders or not. Put a collider on your hole and give a OnTriggerEnter function that checks if the ball goes in, load the next level.

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 gregoriuseggi · Jun 23, 2020 at 09:44 AM 0
Share

welll, make sense but i still didnt get it, can u translate it to code?

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

129 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

Related Questions

next level 1 Answer

How do I make the screen fade when it goes into the next level? 0 Answers

Load Level on Collision 1 Answer

How to script a death fall and respawn? 0 Answers

collision script to next scene 2 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