- Home /
 
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
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.
@PouletFrit Yeah, I didn't know that return would make it finish the statement Thanks again
Your answer
 
             Follow this Question
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