• 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 UltraProgramer · May 09, 2017 at 05:44 AM · unity 5scripting problem

I need help on a unity script!

So I have been following Brackeys — How to make a Video Game in Unity and I was on ep.9 (https://www.youtube.com/watchv=Iv7A8TzreY4∈dex=10&list=PLPV2KyIb3jR53Jce9hP7G5xC4O9AgnOuL) Where you make winning levels but to make sure it works we Debugged it but nothing happens! Is it just because he is using Unity 5.5 and I’m using 5.6 or is there a problem with my script? Here they are that: (GameManager.cs)

 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class GameManager : MonoBehaviour {
     // Variables
     bool gameHasEnded = false;
     public float restartDelay = 1f;
 
     public void  CompleteLevel ()
     {
         Debug.Log (“You Win!”);
     }
 
     public void EndGame ()
     {
         if (gameHasEnded == false)
         {
             gameHasEnded = true;
             Debug.Log(“You Lose!”);
             Invoke(“Restart”, restartDelay);
             // Restart Cube Run game
         }
     }
 
     void Restart ()
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene ().name);
     }
 }

——————————————————————————-

(EndTrigger.cs)

 using UnityEngine;
 
 public class EndTrigger : MonoBehaviour {
     public GameManager gameManager;
 
     void OnTriggerEnter ()
     {
         gameManager.CompleteLevel();
     }
 }

Thank you for helping!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Piyush_Pandey · May 09, 2017 at 07:59 AM

You can check if the OnTriggerEnter() method is getting called or not buy using a debug log there. For OnTriggerEnter() to work , the object which is having EndTrigger script, its collider must have isTriggerd enabled in the collider component and out of the 2 colliding objects, one must have a rigidbody according to unity.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

UniRPG Error cs0121. 0 Answers

The raycasthit does not see the cillider when hitting it 2 Answers

Learn: Survival Shooter aim offset from mouse position 1 Answer

how to view 3d model fully controllable in unity 5 0 Answers

Why do placing a preprocessor directive inside another causes my script to lose proper indentation? 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