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
0
Question by christian24689000 · Oct 27, 2017 at 12:12 AM · collidertriggerplayer movementfadeoutenable and disable script

Locking the player movement and fading out when entering a trigger

Currently, I have two scripts. I have a FadeOut script (which fades the screen to black) and a TriggerFade script so the only time the FadeOut script works is when the player walks into the trigger.
I need help with the keeping the FadeOut script disabled until the player walks into the trigger.

As of right now, the game loads with the fade to black and after the player walks into the trigger the error message: "NullReferenceException: Object reference not set to an instance of an object TriggerFade.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/TriggerFade.cs:12)" pops up


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

public class FadeOut : MonoBehaviour {

 public Texture2D fadeOutTexture;
 public float fadeSpeed = .8f;

 private int drawDepth = 1000;
 private float alpha = 1f;
     private int fadeDir = -1;

 void OnGUI()
 {

     alpha += fadeDir * fadeSpeed * Time.deltaTime;
     alpha = Mathf.Clamp01(alpha);

     GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha);
     GUI.depth = drawDepth;
     GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);

 }
 
 public float BeginFade (int direction)
 {
     fadeDir = direction;
     return (fadeSpeed);
 }

     void OnLevelWasLoaded()
 {
     BeginFade(-1);
 }

}

that was my "FadeOut" script.


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

public class TriggerFade : MonoBehaviour {

 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player")
     {
         FadeOut fadeOut = other.gameObject.GetComponent<FadeOut>();
         fadeOut.enabled = true;     
     }
 }

}

And this was my "TriggerFade script". I also don't want the player to move until the screen completely fades out, or let the player move but keep the screen fading no matter what (Until it stops and the player gets sent to the next scene)


I would also just like to say that I know there are a lot of questions like this, but I'm a beginner so it's still hard for me to look at a line of code and know how to alter it to my own needs. Sorry.

Comment
Add comment · Show 1
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 christian24689000 · Oct 27, 2017 at 12:16 AM 0
Share

Both scripts are in C# by the way

0 Replies

· Add your reply
  • Sort: 

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

143 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

Related Questions

What does the other in OnTriggerEnter/Stay/Exit mean? 0 Answers

AI and Enemy Detection 1 Answer

Change Scene with Physics Raycasting 1 Answer

How to Destroy A GameObject when it enters any Triggers 2 Answers

OnTriggerEnter2D Not Detecting BoxCollider2D - Childed Object 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