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 JacobHockey13 · May 29, 2014 at 02:09 PM · instantiatefunctionif-statements

Object will not instantiate

I have the worst type of problem, in that my prefab will not instantiate but I am not getting any error messages. I am in 2d and is not even coming into the scene. Hopefully, it will be an egregious mistake that was obvious. As of now though, I am puzzled. As a side note, I am changing booleans in the same function and that works perfectly. Also, ignore the commented out code because that's to delete the object which I will only worry about after I can get it into the scene. Here is the code.

 #pragma strict
  
 
 var theHilight : GameObject;
 var place1 = Vector3(-1,0,0);
 
 public static var scaryimage1bool : boolean = true;
 public static var scaryimage2bool : boolean = false;
 public static var scaryimage3bool : boolean = false;
 
 
 
 function OnMouseUpAsButton () {
 ChangeBool11 ();
 ChangeBool12 ();
 ChangeBool13 ();
 }
 
 function ChangeBool11 () {
 if (scaryimage1bool == true) {
 Debug.Log("redundant");
 } else {
 scaryimage1bool = true;
 return scaryimage1bool;
 var hilight1 : GameObject = Instantiate(theHilight, place1, transform.rotation);
 }
 }
 
 
 function ChangeBool12 () {
 if (scaryimage2bool == false) {
 Debug.Log("redundant");
 } else {
 scaryimage2bool = false;
 return scaryimage2bool;
 //if (hilight2 != null) {
 //Destroy(hilight2);
 //}
 }
 }
 
 
 function ChangeBool13 () {
 if (scaryimage3bool == false) {
 Debug.Log("redundant");
 } else {
 scaryimage3bool = false;
 return scaryimage3bool;
 //if (hilight3 != null) {
 //Destroy(hilight3);
 //}
 }
 }
 

Thank you for your help

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

Answer by PouletFrit · May 29, 2014 at 03:25 PM

Your are having a return statement right before your Instantiate statement, which mean that your exiting your function before you go through the Instantiate statement.

 function ChangeBool11 () {
     if (scaryimage1bool == true) {
         Debug.Log("redundant");
     } else {
         scaryimage1bool = true;
         return scaryimage1bool;
         var hilight1 : GameObject = Instantiate(theHilight, place1, transform.rotation);
     }
 }

just change it for:

 function ChangeBool11 () {
     if (scaryimage1bool == true) {
         Debug.Log("redundant");
     } else {
         scaryimage1bool = true;
         var hilight1 : GameObject = Instantiate(theHilight, place1, transform.rotation);
         return scaryimage1bool;
     }
 }

but from what I see from your code, you could also just remove the return statement. There is no need to return the value, since your variable is global.

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 JacobHockey13 · May 29, 2014 at 08:01 PM 0
Share

Thanks man

avatar image JacobHockey13 · May 29, 2014 at 08:04 PM 0
Share

@PouletFrit Yeah, I didn't know that return would make it finish the statement Thanks again

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

21 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

Related Questions

Multiple Cars not working 1 Answer

Creating a Loadout 1 Answer

Remeber the value between frame Update() 1 Answer

Add instantiate object to GameObject[] 2 Answers

How do i change this numbers color for GUI.Label? 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