• 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 /
This question was closed Nov 27, 2015 at 06:57 PM by Ashia40 for the following reason:

Resolved

avatar image
0
Question by Ashia40 · Nov 27, 2015 at 04:50 PM · c#gameobjectinstantiatescript error

instantiate a gameobject since another script

Hello people, I have a small problem.

In fact I would want to instantiate a gameobject since another script.

Here is the error that I reçoi:NullReferenceException: Object references not set to the year authority of the object year GenDongeon.geng () (at Assets Assets/Scripts/GenDongeon.cs:30 Scripts) GenDongeon+pause > c __ Iterator0. MoveNext () (at Assets Assets/Scripts/GenDongeon.cs:21 Scripts)

Thank you.

Sorry for my bad English, because I am French.

Script Salles :

 using UnityEngine;
 using System.Collections;
 
 public class Salles : MonoBehaviour {
 
     public GameObject [] salleg1;
     public GameObject [] salled1;
     public GameObject [] salleu1;
     public GameObject [] salleb1;
 
     public static GameObject [] salleg;
     public static GameObject [] salled;
     public static GameObject [] salleu;
     public static GameObject [] salleb;
 
     public static int salg;
     public static int sald;
     public static int salu;
     public static int salb;
 
     void start(){
 
         salleg = new GameObject[salleg1.Length];
         salled = new GameObject[salled1.Length];
         salleu = new GameObject[salleu1.Length];
         salleb = new GameObject[salleb1.Length];
 
         salg = salleg1.Length;
         sald = salled1.Length;
         salu = salleu1.Length;
         salb = salleb1.Length;
 
         for(int a=0;a<salleg1.Length;a++){
             salleg[a] = salleg1[a];
         }
         for(int b=0;b<salled1.Length;b++){
             salled[b] = salled1[b];
         }
         for(int c=0;c<salleu1.Length;c++){
             salleu[c] = salleu1[c];
         }
         for(int d=0;d<salleb1.Length;d++){
             salleb[d] = salleb1[d];
         }
     }
 }

Script GenDongeon :

 using UnityEngine;
 using System.Collections;
 
 public class GenDongeon : MonoBehaviour {
 
     public bool g;
     public bool d;
     public bool u;
     public bool b;
 
     public int timep;
 
     void Start () {
 
         StartCoroutine (pause());
 
     }
 
     public IEnumerator pause(){
         yield return new WaitForSeconds(timep);
         geng();
         gend();
         genu();
         genb();
     }
 
     void geng(){
         if(g==true){
             int rand = Random.Range (0,Salles.sald);
             Instantiate (Salles.salled[rand],new Vector3(this.transform.position.x-8,this.transform.position.y,0),Quaternion.identity);
         }
     }
 
     void gend(){
         if(d==true){
             int rand = Random.Range (0,Salles.salg);
             Instantiate (Salles.salleg[rand],new Vector3(this.transform.position.x+8,this.transform.position.y,0),Quaternion.identity);
         }
     }
 
     void genu(){
         if(u==true){
             int rand = Random.Range (0,Salles.salb);
             Instantiate (Salles.salleb[rand],new Vector3(this.transform.position.x,this.transform.position.y+8,0),Quaternion.identity);
         }
     }
 
     void genb(){
         if(b==true){
             int rand = Random.Range (0,Salles.salu);
             Instantiate (Salles.salleu[rand],new Vector3(this.transform.position.x,this.transform.position.y-8,0),Quaternion.identity);
         }
     }
 }
 

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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by pekalicious · Nov 27, 2015 at 05:58 PM

In Salles, "start" method should be "Start". Case matters.

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
avatar image
0

Answer by Ashia40 · Nov 27, 2015 at 06:56 PM

Thank you.

Comment
Add comment · Show 1 · 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 pekalicious · Nov 27, 2015 at 06:58 PM 0
Share

No problem. Please accept my answer as correct. Thanks.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

40 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

Related Questions

Game Object doesn't instantiate at Mouse Position 3 Answers

Problems instatiating one gameobject but not others 0 Answers

No gameobject instance again in update 1 Answer

How to instantiate a game object every time when space key is pressed 2 Answers

Instantiate as child for gameobjects with tag 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges