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 /
  • Help Room /
avatar image
-1
Question by Mrkrisher · Nov 03, 2016 at 08:39 PM · teleportrestartautomaticportalrestart game

Creating an Auto-Restart

I have a game where you roll a ball around and collect a bunch of yellow cubes. I have a restart button already, so the player can click it when they mess up or want to restart, but I want there to be an auto-restart/teleport/portal so that if the player falls to the lower ground, they get sent back to the starting position, and their score resets. Here is a small picture. alt text

All answers are appreciated! Thanks in advance!

screen-shot-2016-11-03-at-43429-pm.png (129.0 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

2 Replies

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

Answer by Alokdo · Nov 04, 2016 at 02:48 AM

Try putting a cube where when the player touch the cube, the game will restart.

Remove the "Mesh renderer" (or not, but the cube will be able to see) and, in the BoxCollider check the parameter "is trigger"

Now, make a script (JavaScript or UnityScript) with the following:

 #pragma strict
 
 function OnTriggerEnter (other: Collider){
     //Here is where you need to put your restart code, the same code as the button
 }

Attach the script to the cube and try it.

Tell me if it worked. Greets

Comment
Add comment · Show 7 · 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 Mrkrisher · Nov 04, 2016 at 11:53 PM -1
Share

$$anonymous$$y restart button was a C sharp script, so will the same code work on Java?

avatar image Alokdo Mrkrisher · Nov 05, 2016 at 12:24 AM 0
Share

Ok, use this code ins$$anonymous$$d:

 using UnityEngine;
 using System.Collections;
 
 public class SCRIPTNA$$anonymous$$E : $$anonymous$$onoBehaviour {
     void OnTriggerEnter(Collider other) {
         //Here is wher you need to put your restart code, the same code as the button
     }
 }

Where it says "SCRIPTNA$$anonymous$$E" put the name of your script.

avatar image Mrkrisher · Nov 05, 2016 at 02:46 AM -1
Share

Says there are compiler errors with the script.

Here is my RESTART BUTTON script: alt text

Here is the one I am trying to create now, the AUTO-RESTART script: alt text

Tell me if I should make any changes.

avatar image Alokdo Mrkrisher · Nov 07, 2016 at 08:47 PM 0
Share

Please, if you can, write the code in the commentary, because the images are broken.

avatar image Mrkrisher · Nov 08, 2016 at 01:12 AM -1
Share

RESTART:

using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement; using System.Collections;

public class Restart : $$anonymous$$onoBehaviour {

 public void RestartGame() { Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name); // loads current scene
 }


AUTO-RESTART:

using UnityEngine;

using UnityEngine.Scene$$anonymous$$anagement;

using System.Collections;

public class Background : $$anonymous$$onoBehaviour {

 void OnTriggerEvent (Collider other) {

 public void RestartGame()

{

Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name); // loads current scene

}

}

}

(I know this is confusing but I didn't know how else to put it without a picture.)

avatar image Alokdo Mrkrisher · Nov 09, 2016 at 07:33 PM 0
Share

The name of this script will be "Restart" (without quotes)

Ok, this needs to work (i tested it):

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Scene$$anonymous$$anagement;
 
     public class Restart : $$anonymous$$onoBehaviour {
         void OnTriggerEnter(Collider other) {
             Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name);
         }
     }
 
avatar image Mrkrisher Alokdo · Nov 09, 2016 at 08:19 PM -1
Share

Got it! Thank you!

avatar image
0

Answer by PizzaPie · Nov 08, 2016 at 02:12 PM

Well or you can have a simple statement like this

 float someValue;
  void Update()
     {
             if(player.transform.position.y <someValue)
                       RestartGame();
     }

set the someValue to a point below your plane and it should work. That way you don't have to place triggers all around the plane but it have some restrictions on the way you design the level. (if you attach that code to the player change the statement to gameObject.transform.position.y)

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 Mrkrisher · Nov 08, 2016 at 10:11 PM -1
Share

alt text

Any idea on what I should do?

avatar image PizzaPie Mrkrisher · Nov 09, 2016 at 04:43 PM 0
Share

Can't see the image.

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

59 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

Related Questions

Restart level instead of restart to main menu 2 Answers

How to make an ordered pile of gameObjects during the game? 1 Answer

Rotating object to another objects rotation [C#] 1 Answer

Restart Issue 1 Answer

error: Assets/scripts/Gamemaneger.cs(27,51): error CS1525: Unexpected symbol `)' 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