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 grkpektis · Apr 19, 2016 at 06:58 PM · colorenum

color is not changing in enum code

I can't get this script to work, I am trying to get an object to change color based on what I drag into it. I don't get errors when I build the code but I do when I play the game and try to drag in the objects. Please help

(edit) Here are the errors I get

NullReferenceException: Object reference not set to an instance of an object CollisionAction.DoRed (UnityEngine.GameObject destroyObject) (at Assets/Scripts/CollisionAction.cs:48) CollisionAction.OnCollisionEnter (UnityEngine.Collision other) (at Assets/Scripts/CollisionAction.cs:29)

NullReferenceException: Object reference not set to an instance of an object CollisionAction.DoBlue (UnityEngine.GameObject destroyObject) (at Assets/Scripts/CollisionAction.cs:65) CollisionAction.OnCollisionEnter (UnityEngine.Collision other) (at Assets/Scripts/CollisionAction.cs:26)

     bool activated;
 int value;

 private MeshRenderer wallRenderer;
 private Material wallMaterial;
 private CollisionProperty colPop;

 void Awake (){
     wallRenderer = GetComponent<MeshRenderer> ();
     wallMaterial = wallRenderer.material;
     colPop = GetComponent<CollisionProperty> ();
 }

 void OnCollisionEnter(Collision other){
     CollisionProperty cp = other.gameObject.GetComponent<CollisionProperty> ();

     if (cp != null){
         switch (cp.myProp)
         {
         case CollisionProperty.PropType.blue:
             DoBlue (other.gameObject);
             break;
         case CollisionProperty.PropType.red:
             DoRed (other.gameObject);
             break;
         case CollisionProperty.PropType.green:
             DoGreen ();
             break;
         case CollisionProperty.PropType.yellow:
             DoYellow();
             break;
         case CollisionProperty.PropType.goal1:
             DoG1();
             break;
         case CollisionProperty.PropType.goal2:
             DoG2();
             break;
         }
     }
 }
 
 public void DoRed(GameObject destroyObject){
     if (activated == false && (colPop.myProp != CollisionProperty.PropType.red)) {
         activated = true;
         Destroy (destroyObject.gameObject);
         wallMaterial.color = Color.red;
         colPop.myProp = CollisionProperty.PropType.red;
         StartCoroutine (countdown ());
     } else if (colPop.myProp == CollisionProperty.PropType.red) {
         //add more points because it is the same color
     } else {
         activated= true;
         Destroy (destroyObject.gameObject);
         wallMaterial.color = Color.red;
         //just changed color
     }
 }
 
 public void DoBlue(GameObject destroyObject){
     if (activated == false && (colPop.myProp != CollisionProperty.PropType.blue)) {
         activated = true;
         Destroy (destroyObject.gameObject);
         wallMaterial.color = Color.blue;
         colPop.myProp = CollisionProperty.PropType.blue;
         StartCoroutine (countdown ());
     } else if (colPop.myProp == CollisionProperty.PropType.blue) {
         //add more points because it is the same color
     } else {
         activated= true;
         Destroy (destroyObject.gameObject);
         wallMaterial.color = Color.blue;
         //just changed color
     }
 }
 public void DoGreen(){

 }
 
 public void DoYellow(){

 }
 public void DoG1(){

 }
 public void DoG2(){

 }
 IEnumerator countdown()
 {
     yield return new WaitForSeconds(5);
     activated = false;
     Debug.Log ("false");
 }

}

Comment
Add comment · Show 3
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 Jessespike · Apr 19, 2016 at 08:42 PM 0
Share

what is the error? you can also add Debug.Logs and check the log file to help deter$$anonymous$$e the problem. It might be trying to access an object that has been recently destroyed.

avatar image grkpektis Jessespike · Apr 20, 2016 at 03:26 PM 0
Share

NullReferenceException: Object reference not set to an instance of an object CollisionAction.DoBlue (UnityEngine.GameObject destroyObject) (at Assets/Scripts/CollisionAction.cs:65) CollisionAction.OnCollisionEnter (UnityEngine.Collision other) (at Assets/Scripts/CollisionAction.cs:26)

NullReferenceException: Object reference not set to an instance of an object CollisionAction.DoRed (UnityEngine.GameObject destroyObject) (at Assets/Scripts/CollisionAction.cs:48) CollisionAction.OnCollisionEnter (UnityEngine.Collision other) (at Assets/Scripts/CollisionAction.cs:29)

avatar image Jessespike · Apr 20, 2016 at 07:55 PM 0
Share

Ye it's trying to destroy a null object. I don't know why though. Are there many overlapping colliders? I mean, if you drop the object onto 3 colliders, it will only work once cause it gets destroyed.

An immediate bandage to remove the error would be to check if the object exists before destroying it. Though, this doesn't really solve the problem, more like ignoring it. You need to figure out why destroyObject is null.

 if (destroyObject != null) Destroy(destroyObject);

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

55 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

Related Questions

How can I change the alpha value of multicolored text to 0? 1 Answer

Get color between 2 colors 0 Answers

change color 2 Answers

How to Change the Color of Text without using Markup Text? 0 Answers

Need help to make a color replace shader 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